简体   繁体   中英

How can I change the django-behave test runner's test file discovery pattern?

I have a Django project with behave features and unittest tests. The unittest tests are organized like so:

theproject/
    theapp/
        tests/
            tests_one.py
            tests_other.py
            ...

It is irritating to have to prefix test files, which are already clearly identified as such by being in the tests directory, with "tests_".

If I rename all the test files without "tests_" and change my test runner to

TEST_RUNNER = 'django.test.runner.DiscoverRunner'

in settings.py and do

python manage.py test -p '*.py'

all of my unittest tests run, but not my behave features.

When I have

TEST_RUNNER = 'django_behave.runner.DjangoBehaveTestSuiteRunner'

in settings.py and do

python manage.py test

my features run but not my unittest tests.

The django-behave runner doesn't have a -p flag or an equivalent that I can see.

How can I get the django-behave runner to discover tests in files whose names don't begin with "tests_"?

I solved this problem by switching from django-behave to behave-django.

behave-django does not need the Django TEST_RUNNER to be set to its own test runner, so python manage.py test -p '*.py' works.

behave-django doesn't provide a single Django management command that runs both unit and acceptance tests. I solved that problem by writing a new management command.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM