简体   繁体   English

Pytest 未在子目录中找到所有测试

[英]Pytest not finding all tests in subdirectories

I'm having trouble getting pytest to run all my test cases in all sub directories我无法让 pytest 在所有子目录中运行我的所有测试用例

When I run pytest -v -s in the Project directory, it only ends up finding all the test cases in ComponentB and can't find ComponentA test cases.当我在Project目录中运行pytest -v -s时,它最终只能找到ComponentB所有测试用例,而找不到ComponentA测试用例。

Test cases run fine when I navigate to the respective component directories and run the pytest command.当我导航到相应的组件目录并运行pytest命令时,测试用例运行良好。 Why is pytest skipping ComponentA when run at the top level?为什么 pytest 在顶层运行时会跳过ComponentA

Project/
|____ComponentA/
|   |____srcs
|   |____tests
|        |__test_A_1.py
|        |__test_A_2.py
|        .
|        .
|        .
|____ComponentB/
|   |____srcs
|   |____tests
|        |__test_B_1.py
|        |__test_B_2.py
|        .
|        .
|        .

I assume the file names in your question are just examples but check if your real file names match the conventions for test discovery :我假设您问题中的文件名只是示例,但请检查您的真实文件名是否符合测试发现的约定:

Pytest implements the following standard test discovery: Pytest 实现了以下标准测试发现:

  • If no arguments are specified then collection starts from testpaths (if configured) or the current directory.如果未指定参数,则集合从测试路径(如果已配置)或当前目录开始。 Alternatively, command line arguments can be used in any combination of directories, file names or node ids.或者,可以在目录、文件名或节点 ID 的任意组合中使用命令行参数。
  • Recurse into directories, unless they match norecursedirs.递归到目录中,除非它们匹配 norecursedirs。
  • In those directories, search for test_*.py or *_test.py files , imported by their test package name.在这些目录中,搜索 test_*.py 或 *_test.py files ,按其测试包名称导入。
  • From those files, collect test items:从这些文件中,收集测试项目:
    • test prefixed test functions or methods outside of class测试类外的前缀测试函数或方法
    • test prefixed test functions or methods inside Test prefixed test classes (without an init method) test 前缀测试函数或测试前缀测试类中的方法(没有init方法)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM