pytest icon indicating copy to clipboard operation
pytest copied to clipboard

pytest collection overwrites testcases in monorepo like structure

Open indiVar0508 opened this issue 3 weeks ago • 3 comments

Hi

I have a monorepo, where I have following directory structure

Project/
      repo/
             pkg1/
                     src/
                     tests/
                            …
                            __init__.py
                           test_main.py
             pkg2/
                     src/
                     tests/
                            …
                            __init__.py
                           test_main.py

I also have other mini packages which don’t follow src layout, I have added —import-mode=importlib in root pyproject for addopts But what I am seeing is test_main.py for pkg2 gets overwritten for pkg1 I.e. in test_main.py for pkg1 I have 3 test cases and in test_main.py for pkg2 I have 8 tests cases, but when I see in logs of pytest I see

…
pkg2/tests/test_main . . . # should have eight

From my understand and my guess is this is happening because when pytest resolves unique path for each it might be picking tests.test_main for both.

I tried verbose run and I can see the test name from pkg1 in path of pkg2

I needed some help guidance / help to point me in right direction to properly setup this for my usecase

Thanks !

Originally posted by @indiVar0508 in https://github.com/pytest-dev/pytest/discussions/13749

indiVar0508 avatar Nov 22 '25 11:11 indiVar0508