25
25
import _pytest ._code
26
26
from _pytest import nodes
27
27
from _pytest .compat import final
28
+ from _pytest .compat import LEGACY_PATH
28
29
from _pytest .compat import legacy_path
29
30
from _pytest .config import Config
30
31
from _pytest .config import directory_arg
@@ -301,7 +302,7 @@ def wrap_session(
301
302
finally :
302
303
# Explicitly break reference cycle.
303
304
excinfo = None # type: ignore
304
- session . startdir . chdir ()
305
+ os . chdir (session . startpath )
305
306
if initstate >= 2 :
306
307
try :
307
308
config .hook .pytest_sessionfinish (
@@ -476,7 +477,6 @@ def __init__(self, config: Config) -> None:
476
477
self .shouldstop : Union [bool , str ] = False
477
478
self .shouldfail : Union [bool , str ] = False
478
479
self .trace = config .trace .root .get ("collection" )
479
- self .startdir = config .invocation_dir
480
480
self ._initialpaths : FrozenSet [Path ] = frozenset ()
481
481
482
482
self ._bestrelpathcache : Dict [Path , str ] = _bestrelpath_cache (config .rootpath )
@@ -497,6 +497,24 @@ def __repr__(self) -> str:
497
497
self .testscollected ,
498
498
)
499
499
500
+ @property
501
+ def startpath (self ) -> Path :
502
+ """The path from which pytest was invoked.
503
+
504
+ .. versionadded:: 6.3.0
505
+ """
506
+ return self .config .invocation_params .dir
507
+
508
+ @property
509
+ def stardir (self ) -> LEGACY_PATH :
510
+ """The path from which pytest was invoked.
511
+
512
+ Prefer to use ``startpath`` which is a :class:`pathlib.Path`.
513
+
514
+ :type: LEGACY_PATH
515
+ """
516
+ return legacy_path (self .startpath )
517
+
500
518
def _node_location_to_relpath (self , node_path : Path ) -> str :
501
519
# bestrelpath is a quite slow function.
502
520
return self ._bestrelpathcache [node_path ]
0 commit comments