|
6 | 6 | import sys |
7 | 7 | import textwrap |
8 | 8 |
|
| 9 | +import py |
| 10 | + |
9 | 11 | import pytest |
10 | 12 | from _pytest.main import _in_venv |
11 | 13 | from _pytest.main import EXIT_NOTESTSCOLLECTED |
@@ -1051,3 +1053,55 @@ def test_1(): |
1051 | 1053 | result = testdir.runpytest() |
1052 | 1054 | assert result.ret == 0 |
1053 | 1055 | result.stdout.fnmatch_lines(["*1 passed in*"]) |
| 1056 | + |
| 1057 | + |
| 1058 | +@pytest.mark.skipif( |
| 1059 | + not hasattr(py.path.local, "mksymlinkto"), |
| 1060 | + reason="symlink not available on this platform", |
| 1061 | +) |
| 1062 | +def test_collect_symlink_file_arg(testdir): |
| 1063 | + """Test that collecting a direct symlink, where the target does not match python_files works (#4325).""" |
| 1064 | + real = testdir.makepyfile( |
| 1065 | + real=""" |
| 1066 | + def test_nodeid(request): |
| 1067 | + assert request.node.nodeid == "real.py::test_nodeid" |
| 1068 | + """ |
| 1069 | + ) |
| 1070 | + symlink = testdir.tmpdir.join("symlink.py") |
| 1071 | + symlink.mksymlinkto(real) |
| 1072 | + result = testdir.runpytest("-v", symlink) |
| 1073 | + result.stdout.fnmatch_lines(["real.py::test_nodeid PASSED*", "*1 passed in*"]) |
| 1074 | + assert result.ret == 0 |
| 1075 | + |
| 1076 | + |
| 1077 | +@pytest.mark.skipif( |
| 1078 | + not hasattr(py.path.local, "mksymlinkto"), |
| 1079 | + reason="symlink not available on this platform", |
| 1080 | +) |
| 1081 | +def test_collect_symlink_out_of_tree(testdir): |
| 1082 | + """Test collection of symlink via out-of-tree rootdir.""" |
| 1083 | + sub = testdir.tmpdir.join("sub") |
| 1084 | + real = sub.join("test_real.py") |
| 1085 | + real.write( |
| 1086 | + textwrap.dedent( |
| 1087 | + """ |
| 1088 | + def test_nodeid(request): |
| 1089 | + # Should not contain sub/ prefix. |
| 1090 | + assert request.node.nodeid == "test_real.py::test_nodeid" |
| 1091 | + """ |
| 1092 | + ), |
| 1093 | + ensure=True, |
| 1094 | + ) |
| 1095 | + |
| 1096 | + out_of_tree = testdir.tmpdir.join("out_of_tree").ensure(dir=True) |
| 1097 | + symlink_to_sub = out_of_tree.join("symlink_to_sub") |
| 1098 | + symlink_to_sub.mksymlinkto(sub) |
| 1099 | + sub.chdir() |
| 1100 | + result = testdir.runpytest("-vs", "--rootdir=%s" % sub, symlink_to_sub) |
| 1101 | + result.stdout.fnmatch_lines( |
| 1102 | + [ |
| 1103 | + # Should not contain "sub/"! |
| 1104 | + "test_real.py::test_nodeid PASSED" |
| 1105 | + ] |
| 1106 | + ) |
| 1107 | + assert result.ret == 0 |
0 commit comments