我有一种类似于以下内容的“微服务” Python存储库:
sample
├── bar
│ ├── src
│ │ └── main.py
│ └── tests
│ └── test_main.py
├── foo
│ ├── src
│ │ └── main.py
│ └── tests
│ └── test_main.py
└── shared
├── src
│ └── main.py
└── tests
└── test_main.py
在vscode中,我只能选择在foo
,bar
,shared
中运行all测试,或在子文件夹中运行单独的测试methods。我想做的就是能够快速运行foo/tests/
。
是否可以通过某种方式配置pytest / Python来执行此操作?我不想将每个顶级文件夹拆分到自己的工作区中,因为我经常跳回去并在它们之间跳转,并且不想每个工作区都打开多个窗口。
您应该能够根据以下说明在终端中运行命令pytest foo/tests/
pytest documentation
主要有两种选择,
Ctrl
+ ~
来获取命令行pytest foo/tests/
另一种方法是在项目根目录下创建pytest配置文件。配置文件应命名为pytest.ini
。
testpaths
变量分配给所需的文件夹一个示例如下
[pytest]
testpaths = foo
python_files = tests.py test_*.py *_tests.py *.tests.py
这只会在foo目录下运行测试