简体   繁体   中英

Pytest not finding all tests in subdirectories

I'm having trouble getting pytest to run all my test cases in all sub directories

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.

Test cases run fine when I navigate to the respective component directories and run the pytest command. Why is pytest skipping ComponentA when run at the top level?

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:

  • 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.
  • Recurse into directories, unless they match norecursedirs.
  • In those directories, search for test_*.py or *_test.py files , imported by their test package name.
  • 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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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