简体   繁体   中英

Add non app tests to tests that run when executing python manage.py test

My Django project has a few app each with their respective tests. It also has a utils package that has its own tests.

The package utils is in a folder at the same level as manage.py and its tests are in a subfolder called tests in files called test_xxx.py

When I run python manage.py test Django runs all tests for all the apps in my project but it does not run the tests for the utils package. I can run the tests for the utils package by running python manage.py test utils .

What I would like to do is that tests for utils are also run when I run python manage.py test so that single command tests the whole suite for my project. I haven't been able to find anything in the documentation or searching google or here on how to do it. Any ideas?

Thanks for your help!!

--- Additional details ---

Directory structure

├── project
│   ├── __init__.py
│   ├── settings.py
│   ├── urls.py
│   └── wsgi.py
├── manage.py
├── ...
├── app1
│   ├── __init__.py
│   ├── urls.py
│   ├── views.py
│   ├── ...
│   └── tests
│        ├── test_views.py
│        └── test_models.py
├── app2
│   ├── __init__.py
│   ├── urls.py
│   ├── views.py
│   ├── ...
│   └── tests
│        ├── test_views.py
│        └── test_models.py
└── utils
    ├── __init__.py
    ├── code.py
    └── tests
         └── test_utils.py

Command to execute tests

python manage.py test

... that executes ...

nosetests --with-coverage --cover-package=app1,app2, utils --cover-html --cover-erase --logging-filter='selenium' --verbosity=1

And the coverage report shows that all the tests for app1 and app2 have been executed but not the tests for utils

Django uses the DiscoverRunner to run your tests harness. As you can see here: https://docs.djangoproject.com/en/2.1/topics/testing/advanced/#defining-a-test-runner

The first option is:

top_level can be used to specify the directory containing your top-level Python modules. Usually Django can figure this out automatically, so it's not necessary to specify this option. If specified, it should generally be the directory containing your manage.py file.

Therefore your test should be run by the test harness because are in the same folder of your manage.py . Did you add the __init__.py in the tests folder?

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