|
4 | 4 | import py |
5 | 5 | import pytest |
6 | 6 | from _pytest.config import PytestPluginManager |
7 | | -from _pytest.main import EXIT_NOTESTSCOLLECTED, EXIT_USAGEERROR |
| 7 | +from _pytest.main import EXIT_NOTESTSCOLLECTED, EXIT_OK, EXIT_USAGEERROR |
8 | 8 |
|
9 | 9 |
|
10 | 10 | @pytest.fixture(scope="module", params=["global", "inpackage"]) |
@@ -186,6 +186,52 @@ def pytest_addoption(parser): |
186 | 186 | assert "warning: could not load initial" not in result.stdout.str() |
187 | 187 |
|
188 | 188 |
|
| 189 | +@pytest.mark.skipif( |
| 190 | + not hasattr(py.path.local, "mksymlinkto"), |
| 191 | + reason="symlink not available on this platform", |
| 192 | +) |
| 193 | +def test_conftest_symlink(testdir): |
| 194 | + """Ensure that conftest.py is used for resolved symlinks.""" |
| 195 | + realtests = testdir.tmpdir.mkdir("real").mkdir("app").mkdir("tests") |
| 196 | + testdir.tmpdir.join("symlinktests").mksymlinkto(realtests) |
| 197 | + testdir.makepyfile( |
| 198 | + **{ |
| 199 | + "real/app/tests/test_foo.py": "def test1(fixture): pass", |
| 200 | + "real/conftest.py": textwrap.dedent( |
| 201 | + """ |
| 202 | + import pytest |
| 203 | +
|
| 204 | + print("conftest_loaded") |
| 205 | +
|
| 206 | + @pytest.fixture |
| 207 | + def fixture(): |
| 208 | + print("fixture_used") |
| 209 | + """ |
| 210 | + ), |
| 211 | + } |
| 212 | + ) |
| 213 | + result = testdir.runpytest("-vs", "symlinktests") |
| 214 | + result.stdout.fnmatch_lines( |
| 215 | + [ |
| 216 | + "*conftest_loaded*", |
| 217 | + "real/app/tests/test_foo.py::test1 fixture_used", |
| 218 | + "PASSED", |
| 219 | + ] |
| 220 | + ) |
| 221 | + assert result.ret == EXIT_OK |
| 222 | + |
| 223 | + realtests.ensure("__init__.py") |
| 224 | + result = testdir.runpytest("-vs", "symlinktests/test_foo.py::test1") |
| 225 | + result.stdout.fnmatch_lines( |
| 226 | + [ |
| 227 | + "*conftest_loaded*", |
| 228 | + "real/app/tests/test_foo.py::test1 fixture_used", |
| 229 | + "PASSED", |
| 230 | + ] |
| 231 | + ) |
| 232 | + assert result.ret == EXIT_OK |
| 233 | + |
| 234 | + |
189 | 235 | def test_no_conftest(testdir): |
190 | 236 | testdir.makeconftest("assert 0") |
191 | 237 | result = testdir.runpytest("--noconftest") |
|
0 commit comments