File tree 3 files changed +18
-2
lines changed 3 files changed +18
-2
lines changed Original file line number Diff line number Diff line change
1
+ Fix collection of direct symlinked files.
Original file line number Diff line number Diff line change @@ -488,7 +488,7 @@ def _collect(self, arg):
488
488
from _pytest .python import Package
489
489
490
490
names = self ._parsearg (arg )
491
- argpath = names .pop (0 ). realpath ()
491
+ argpath = names .pop (0 )
492
492
493
493
# Start with a Session root, and delve to argpath item (dir or file)
494
494
# and stack all Packages found on the way.
@@ -636,7 +636,7 @@ def _parsearg(self, arg):
636
636
"file or package not found: " + arg + " (missing __init__.py?)"
637
637
)
638
638
raise UsageError ("file not found: " + arg )
639
- parts [0 ] = path
639
+ parts [0 ] = path . realpath ()
640
640
return parts
641
641
642
642
def matchnodes (self , matching , names ):
Original file line number Diff line number Diff line change 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,16 @@ 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 works (#4325)."""
1064
+ p = testdir .makepyfile ("def test_1(): pass" )
1065
+ testdir .tmpdir .join ("symlink.py" ).mksymlinkto (p )
1066
+ result = testdir .runpytest ("--collect-only" , "symlink.py" )
1067
+ result .stdout .fnmatch_lines (["collected 1 item" ])
1068
+ assert result .ret == 0
You can’t perform that action at this time.
0 commit comments