Co-authored-by: Bruno Oliveira <nicoddemus@gmail.com>
This commit is contained in:
@@ -7,6 +7,7 @@ import pytest
|
||||
from _pytest.config import ExitCode
|
||||
from _pytest.config import PytestPluginManager
|
||||
from _pytest.pathlib import Path
|
||||
from _pytest.pathlib import symlink_or_skip
|
||||
|
||||
|
||||
def ConftestWithSetinitial(path):
|
||||
@@ -190,16 +191,25 @@ def test_conftest_confcutdir(testdir):
|
||||
result.stdout.no_fnmatch_line("*warning: could not load initial*")
|
||||
|
||||
|
||||
@pytest.mark.skipif(
|
||||
not hasattr(py.path.local, "mksymlinkto"),
|
||||
reason="symlink not available on this platform",
|
||||
)
|
||||
def test_conftest_symlink(testdir):
|
||||
"""Ensure that conftest.py is used for resolved symlinks."""
|
||||
"""
|
||||
conftest.py discovery follows normal path resolution and does not resolve symlinks.
|
||||
"""
|
||||
# Structure:
|
||||
# /real
|
||||
# /real/conftest.py
|
||||
# /real/app
|
||||
# /real/app/tests
|
||||
# /real/app/tests/test_foo.py
|
||||
|
||||
# Links:
|
||||
# /symlinktests -> /real/app/tests (running at symlinktests should fail)
|
||||
# /symlink -> /real (running at /symlink should work)
|
||||
|
||||
real = testdir.tmpdir.mkdir("real")
|
||||
realtests = real.mkdir("app").mkdir("tests")
|
||||
testdir.tmpdir.join("symlinktests").mksymlinkto(realtests)
|
||||
testdir.tmpdir.join("symlink").mksymlinkto(real)
|
||||
symlink_or_skip(realtests, testdir.tmpdir.join("symlinktests"))
|
||||
symlink_or_skip(real, testdir.tmpdir.join("symlink"))
|
||||
testdir.makepyfile(
|
||||
**{
|
||||
"real/app/tests/test_foo.py": "def test1(fixture): pass",
|
||||
@@ -216,38 +226,20 @@ def test_conftest_symlink(testdir):
|
||||
),
|
||||
}
|
||||
)
|
||||
|
||||
# Should fail because conftest cannot be found from the link structure.
|
||||
result = testdir.runpytest("-vs", "symlinktests")
|
||||
result.stdout.fnmatch_lines(
|
||||
[
|
||||
"*conftest_loaded*",
|
||||
"real/app/tests/test_foo.py::test1 fixture_used",
|
||||
"PASSED",
|
||||
]
|
||||
)
|
||||
assert result.ret == ExitCode.OK
|
||||
result.stdout.fnmatch_lines(["*fixture 'fixture' not found*"])
|
||||
assert result.ret == ExitCode.TESTS_FAILED
|
||||
|
||||
# Should not cause "ValueError: Plugin already registered" (#4174).
|
||||
result = testdir.runpytest("-vs", "symlink")
|
||||
assert result.ret == ExitCode.OK
|
||||
|
||||
realtests.ensure("__init__.py")
|
||||
result = testdir.runpytest("-vs", "symlinktests/test_foo.py::test1")
|
||||
result.stdout.fnmatch_lines(
|
||||
[
|
||||
"*conftest_loaded*",
|
||||
"real/app/tests/test_foo.py::test1 fixture_used",
|
||||
"PASSED",
|
||||
]
|
||||
)
|
||||
assert result.ret == ExitCode.OK
|
||||
|
||||
|
||||
@pytest.mark.skipif(
|
||||
not hasattr(py.path.local, "mksymlinkto"),
|
||||
reason="symlink not available on this platform",
|
||||
)
|
||||
def test_conftest_symlink_files(testdir):
|
||||
"""Check conftest.py loading when running in directory with symlinks."""
|
||||
"""Symlinked conftest.py are found when pytest is executed in a directory with symlinked
|
||||
files."""
|
||||
real = testdir.tmpdir.mkdir("real")
|
||||
source = {
|
||||
"app/test_foo.py": "def test1(fixture): pass",
|
||||
@@ -271,7 +263,7 @@ def test_conftest_symlink_files(testdir):
|
||||
build = testdir.tmpdir.mkdir("build")
|
||||
build.mkdir("app")
|
||||
for f in source:
|
||||
build.join(f).mksymlinkto(real.join(f))
|
||||
symlink_or_skip(real.join(f), build.join(f))
|
||||
build.chdir()
|
||||
result = testdir.runpytest("-vs", "app/test_foo.py")
|
||||
result.stdout.fnmatch_lines(["*conftest_loaded*", "PASSED"])
|
||||
|
||||
Reference in New Issue
Block a user