pytest fixtures in a separate directory

后端 未结 3 894
渐次进展
渐次进展 2020-12-16 14:35

I\'m looking to create a pytest structure where I can separate the fixtures from the tests completely. The reason for this separation is that I want to include the fixtures

相关标签:
3条回答
  • 2020-12-16 15:23

    read here how structure your test.

    your fixture directory seems not in package (project does not have __init__.py so canno be imported as project.fixtures either as fixtures as is not in the path. You can add required dirs in the path in your tests/conftest.py (sys.path.append(os.path.join(os.path.dirname(__file__), os.pardir, "fixtures")) or sys.path.append(os.path.join(os.path.dirname(__file__), os.pardir) depending how how you want import your modules.

    0 讨论(0)
  • 2020-12-16 15:26

    Did you try importing your fixtures in project/conftest.py? Is that what you mean by "wrappers to return an instance"?

    0 讨论(0)
  • 2020-12-16 15:37

    Please add the following in your conftest.py

      import pytest
    
      pytest_plugins = [
       "fixtures.conftest",
       "fixtures.fixture_cifs",
       "fixtures.fixture_ftp",
       "fixtures.fixture_service"
      ]
    

    This ensures that all fixtures declared under fixtures/ will be found by pytest

    As a note that the respective directories referred to in fixtures.conftest" need to have __init__.py files for the plugins to be loaded by pytest

    A similar case can be seen here: https://stackoverflow.com/a/54736237/6655459

    0 讨论(0)
提交回复
热议问题