- pytest Quick Start Guide
- Bruno Oliveira
- 146字
- 2021-07-16 17:51:29
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.
推薦閱讀
- Application Development with Qt Creator(Second Edition)
- 智能網聯汽車V2X與智能網聯設施I2X
- INSTANT PhpStorm Starter
- 電子政務效益的經濟分析與評價
- Django 2 by Example
- Oracle SOA Suite 11g Performance Tuning Cookbook
- 物聯網概論(第2版)
- 計算機網絡與數據通信
- NB-IoT物聯網技術解析與案例詳解
- Getting Started with Grunt:The JavaScript Task Runner
- 物聯網場景設計與開發(初級)
- 6G無線網絡空口關鍵技術
- 異構蜂窩網絡關鍵理論與技術
- 圖神經網絡前沿
- RestKit for iOS