Hi everyone!

Suppose the following files:

# foo/conftest.py
import pytest
@pytest.fixture
def my_fixture():
    return 1

# foo/__init__.py
<empty file>

# bar/conftest.py
pytest_plugins = ['foo.conftest']

# bar/test_bar.py
def test_it(my_fixture):
    assert my_fixture == 1

Supposing your PYTHONPATH is configured so you can import "foo.conftest",
running "py.test bar" fails because it does not find "my_fixture".

However, if you rename "foo/conftest.py" to something else like
"foo/plugin.py" and update the reference in "bar/conftest.py", then pytest
is able to find "my_fixture".

Looking at the code, I see that there is a special case for "conftest.py"
files in _pytest.python, line 1617. I was wondering what is the rationale
behind this? I was under the impression that "conftest.py" files where
simply plugins which were loaded automatically based on their relative
location to the tests.

In my case, I would like to reuse fixtures defined in conftest files
between different projects.
For instance, project2 depends on project1's fixtures which are defined in
a conftest file, so I would like to simply add a "pytest_plugins =
['project1.conftest']" to project2's own conftest file. If I understand
correctly, I would have to move project1's fixture to a different file, say
"project1.plugin", and reference it in both project1 and project2's
conftest files. Is this the recommended approach?

Cheers,
Bruno
_______________________________________________
pytest-dev mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pytest-dev

Reply via email to