@@ -225,6 +225,8 @@ def pytest_report_teststatus(report, config):
225
225
config -- configuration object.
226
226
"""
227
227
cwd = pathlib .Path .cwd ()
228
+ if SYMLINK_PATH :
229
+ cwd = SYMLINK_PATH
228
230
229
231
if report .when == "call" :
230
232
traceback = None
@@ -348,10 +350,7 @@ def pytest_sessionfinish(session, exitstatus):
348
350
cwd = pathlib .Path .cwd ()
349
351
if SYMLINK_PATH :
350
352
print ("Plugin warning[vscode-pytest]: SYMLINK set, adjusting cwd." )
351
- # Get relative between the cwd (resolved path) and the node path.
352
- rel_path = os .path .relpath (cwd , pathlib .Path .cwd ())
353
- # Calculate the new node path by making it relative to the symlink path.
354
- cwd = pathlib .Path (os .path .join (SYMLINK_PATH , rel_path ))
353
+ cwd = pathlib .Path (SYMLINK_PATH )
355
354
356
355
if IS_DISCOVERY :
357
356
if not (exitstatus == 0 or exitstatus == 1 or exitstatus == 5 ):
@@ -681,9 +680,9 @@ def get_node_path(node: Any) -> pathlib.Path:
681
680
A function that returns the path of a node given the switch to pathlib.Path.
682
681
It also evaluates if the node is a symlink and returns the equivalent path.
683
682
"""
684
- path = getattr (node , "path" , None ) or pathlib .Path (node .fspath )
683
+ node_path = getattr (node , "path" , None ) or pathlib .Path (node .fspath )
685
684
686
- if not path :
685
+ if not node_path :
687
686
raise VSCodePytestError (
688
687
f"Unable to find path for node: { node } , node.path: { node .path } , node.fspath: { node .fspath } "
689
688
)
@@ -692,17 +691,24 @@ def get_node_path(node: Any) -> pathlib.Path:
692
691
if SYMLINK_PATH and not isinstance (node , pytest .Session ):
693
692
# Get relative between the cwd (resolved path) and the node path.
694
693
try :
695
- rel_path = path .relative_to (pathlib .Path .cwd ())
696
-
697
- # Calculate the new node path by making it relative to the symlink path.
698
- sym_path = pathlib .Path (os .path .join (SYMLINK_PATH , rel_path ))
699
- return sym_path
694
+ # check to see if the node path contains the symlink root already
695
+ common_path = os .path .commonpath ([SYMLINK_PATH , node_path ])
696
+ if common_path == os .fsdecode (SYMLINK_PATH ):
697
+ # node path is already relative to the SYMLINK_PATH root therefore return
698
+ return node_path
699
+ else :
700
+ # if the node path is not a symlink, then we need to calculate the equivalent symlink path
701
+ # get the relative path between the cwd and the node path (as the node path is not a symlink)
702
+ rel_path = node_path .relative_to (pathlib .Path .cwd ())
703
+ # combine the difference between the cwd and the node path with the symlink path
704
+ sym_path = pathlib .Path (os .path .join (SYMLINK_PATH , rel_path ))
705
+ return sym_path
700
706
except Exception as e :
701
707
raise VSCodePytestError (
702
708
f"Error occurred while calculating symlink equivalent from node path: { e } "
703
- "\n SYMLINK_PATH: {SYMLINK_PATH}, \n node path: {path }, \n cwd: {{ pathlib.Path.cwd()} }"
709
+ f "\n SYMLINK_PATH: { SYMLINK_PATH } , \n node path: { node_path } , \n cwd: { pathlib .Path .cwd ()} "
704
710
)
705
- return path
711
+ return node_path
706
712
707
713
708
714
__socket = None
0 commit comments