官术网_书友最值得收藏!

Tests separate from your code

An alternative to the method above is to organize your tests in a separate directory from the main package:

setup.py
mylib/
__init__.py
core.py
utils.py
tests/
__init__.py
test_core.py
test_utils.py

Some people prefer this layout because:

  • It keeps library code and testing code separate
  • The testing code is not included in the source package

One disadvantage of the above method is that, once you have a more complex hierarchy, you will probably want to keep the same hierarchy inside your tests directory, and that's a little harder to maintain and keep in sync:

mylib/  
__init__.py
core/
__init__.py
foundation.py
contrib/
__init__.py
text_plugin.py
tests/
__init__.py
core/
__init__.py
test_foundation.py
contrib/
__init__.py
test_text_plugin.py
So, which layout is the best? Both layouts have advantages and disadvantages. Pytest itself works perfectly well with either of them, so feel free to choose a layout that you are more comfortable with.
主站蜘蛛池模板: 克什克腾旗| 宁远县| 铜山县| 诸暨市| 嘉兴市| 达拉特旗| 屏东县| 合江县| 盐池县| 丰都县| 高碑店市| 博客| 龙川县| 遵化市| 郧西县| 桐柏县| 乌海市| 桃源县| 华坪县| 富锦市| 沙田区| 铁岭市| 郓城县| 台江县| 井陉县| 富宁县| 岗巴县| 贵德县| 阳泉市| 大城县| 郴州市| 衡南县| 黄梅县| 溧水县| 准格尔旗| 宿松县| 九江县| 黑山县| 吕梁市| 犍为县| 永嘉县|