Search code examples
djangopytestfixtures

pyest does not detect fixtures in separate folder


I have a Django application and am writing tests using pytest and pytest fixtures.

All the tests are in their respective Django apps but I wrote the fixtures in a different folder as a module.

Project structure:

Proj.
|
+apps: 
  - core
     -tests
        -test_core.py
  - users
      -tests
         test_user.py
|
+fixtures:
   - __init__.py
   - core.py
   - users.py
|
+conftest.py

I have the different fixtures in their separate files which correspond with the app names they are to be used.

Am having problems with pytest detecting the fixtures I have tried creating a conftest.py file in the root of the project and importing the fixtures file as a plugin.

 conftest.py 
 > pytest_plugins = [
    "apps.fixtures",]

I have also tried removing the coftest.py file and placing the fixtures file in the apps folder and still pytest does not detect the fixtures.

Any help here would be helpful.


Solution

  • Plugins are not needed for this, simply import them into conftest.py to make them available to all test files.

    from proj.fixtures.core import *
    from proj.fixtures.users import *