【发布时间】:2019-08-15 02:17:39
【问题描述】:
我正在寻找有关以下情况的最佳实践建议:
- 我正在使用 pytest 在我的 IAC 部署上运行集成测试
- 我的 IAC 代码库结构如下:
myapp
|
|_roles
| |_role1
| |_role2
|_resources
|_tomcat
|_java
我想对我的测试文件使用相同的结构。 测试目前分为文件匹配角色(role1、role2):
tests
|
|_roles
|_test_role1.py
|_test_role2.py
导致重复代码,例如:
role1 是一个 tomcat 基础应用,
role2持有纯java代码,
所以在两个测试文件(test_role1.py 和 test_role2.py)中都会有一个 java 测试函数。
如果我可以将目录结构添加为:
tests
|
|_roles
| |_test_role1.py
| |_test_role2.py
|
|_resources
|_test_tomcat.py
|_test_java.py
然后我可以只“包含/导入” test_java.py 函数以在 test_role1.py 和 test_role2.py 中使用它们,而无需复制代码...
实现这一目标的最佳方法是什么?
我已经在使用固定装置(在 conftest.py 中定义),我觉得我的重复代码的解决方案是固定装置或测试模块,但我糟糕的 python / pytest 知识使我远离实际的解决方案。
谢谢
【问题讨论】: