[英]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. 我的Django项目有几个应用程序,每个应用程序都有各自的测试。 It also has a
utils
package that has its own tests. 它还具有一个
utils
软件包,该软件包具有自己的测试。
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 软件包
utils
位于与manage.py相同级别的文件夹中,而其测试则位于名为test_xxx.py的文件中名为tests的子文件夹中。
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. 当我运行
python manage.py test
Django会为项目中的所有应用程序运行所有测试,但不会为utils
包运行测试。 I can run the tests for the utils
package by running python manage.py test utils
. 我可以通过运行
python manage.py test utils
来运行utils
包的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. 我想做的是,当我运行
python manage.py test
时,也将运行对utils的python manage.py test
以便单个命令测试项目的整个套件。 I haven't been able to find anything in the documentation or searching google or here on how to do it. 我无法在文档中找到任何内容,也无法搜索google或此处的操作方法。 Any ideas?
有任何想法吗?
Thanks for your help!! 谢谢你的帮助!!
--- Additional details --- - - 额外细节 - -
├── 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
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 覆盖率报告显示,针对app1和app2的所有测试均已执行,但未针对utils的测试
Django uses the DiscoverRunner
to run your tests harness. Django使用
DiscoverRunner
运行您的测试工具。 As you can see here: https://docs.djangoproject.com/en/2.1/topics/testing/advanced/#defining-a-test-runner 如您所见: https : //docs.djangoproject.com/zh-CN/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.
top_level可用于指定包含顶级Python模块的目录。 Usually Django can figure this out automatically, so it's not necessary to specify this option.
通常Django可以自动解决此问题,因此无需指定此选项。 If specified, it should generally be the directory containing your manage.py file.
如果指定,则通常应该是包含manage.py文件的目录。
Therefore your test should be run by the test harness because are in the same folder of your manage.py
. 因此,您的测试应由测试工具运行,因为它们位于
manage.py
的同一文件夹中。 Did you add the __init__.py
in the tests folder? 您是否在测试文件夹中添加了
__init__.py
?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.