這是一種不尋常的情況 - 大多數Django用戶都希望Django的測試運行者能夠找到他們所有的測試。如何禁用Django的測試發現?
我正在研究一個Python庫,其中包含多個運行不同配置的測試套件,所以我不想讓發現從錯誤配置中找到並運行測試。如何完全禁用發現,並依賴僅在INSTALLED_APPS中顯式聲明的應用程序運行測試的1.6版之前的行爲?
我的圖書館結構:
library/ # django app used by others
tests/ # custom test suites here
core/ # tests of core functionality
custom/ # tests of a custom feature requiring separate config
contrib/ # tests for assorted contrib features, also requiring separate config
manage_core.py # separate manage.py files for each "project"
manage_custom.py # these specify settings file to use.
manage_contrib.py
settings.py # base settings for all tests
settings_core.py # settings for 'core' tests including unique INSTALLED_APPS
settings_custom.py # settings for 'custom' tests; different INSTALLED_APPS
settings_contrib.py # settings for 'contrib' tests; different INSTALLED_APPS
的問題是,該命令,它應該只對「的contrib」測試套件運行測試,也發現和「核心」運行測試: ./manage_contrib.py test contrib.tests
如果未安裝必要的應用程序,您可以[跳過測試](https://docs.python.org/3/library/unittest.html#skipping-tests-and-expected-failures)。 – knbk