3

I have several packages I want to to write pytest tests for. All the packages should use same fixture logic, so I want to have the common test logic (fixtures) to sit in some common path and each package test should reside in its own path.

Repository 1:
=============
/path/to/PackageA/test_A.py
/path/to/PackageB/test_B.py

Repository 2:
=============
/different_path/to/Common/conftest.py

The problem is that when I run pytest on test_A.py or test_B.py, pytest doesn't find fixtures defined in conftest.py. Tried to play with --confcutdir option, but with no luck...

The only scenario that is working for me is running pytest from /different_path/to/Common/, while setting pytest.ini testpath = /path/to/PackageA/ (BTW running pytest /path/to/PackageA/ didn't work).

alnet
  • 1,093
  • 1
  • 12
  • 24
  • I think what you could try is to import fixtures defined in `/different_path/to/Common/conftest.py` to `/path/to/PackageA/conftest.py` and `/path/to/PackageB/conftest.py`. To do that you have to either add this `Common` directory into your PYTHONPATH or you could import using full path as shown [here](http://stackoverflow.com/questions/67631/how-to-import-a-module-given-the-full-path). – running.t Dec 21 '15 at 15:30

1 Answers1

2

The answer to that problem is to transform Common into a pytest plugin. If you already have a setup.py for that Common project, it is just a matter of adding this to your setup call:

# the following makes a plugin available to pytest
entry_points = {
    'pytest11': [
        'common = Common.plugin',
    ]
},

You will have to rename Common/conftest.py to plugin.py though (or something else other than conftest.py), as py.test treats that file name specially.

If you don't have a setup.py for Common, then you can make py.test use it as a plugin by adding addopts = -p Common.plugin to PackageA/pytest.ini and PackageB/pytest.ini.

Bruno Oliveira
  • 13,694
  • 5
  • 43
  • 41