Conftest discovery with tests as part of application code

31 Views Asked by At

I'm using pytest and decided to go with Tests as part of application code pattern. Everything works fine besides conftest discovery.

I have the following structure:

module_a/
    a.py
    __tests__/
      conftest.py
      test_a.py
    submodule/
        b.py
        __tests__/
            test_b.py

In conftest.py under module_a/__tests__ I define fixtures that I want to be able to use in module_a/submodule/__tests__, but it doesn't discover that. If I move the conftest.py to module_a (not inside __tests__), it works, but I dont want to define it outside of the __tests__ directory.

Any idea how can I achieve this?

1

There are 1 best solutions below

0
Bharel On

Per documentation, conftest.py relates only to subfolders, and not to folders in other locations. You can create the submodule tests under the main __tests__ folder.