@@ -1306,13 +1306,16 @@ def test_rootpath_base(self, pytester: Pytester, monkeypatch: MonkeyPatch) -> No
13061306 from _pytest .assertion import AssertionState
13071307
13081308 config = pytester .parseconfig ()
1309- monkeypatch .chdir (pytester .path )
13101309 state = AssertionState (config , "rewrite" )
1311- assert state .rootpath == str (pytester . path )
1312- new_rootpath = str (pytester .path ) + "/ test"
1310+ assert state .rootpath == str (config . invocation_params . dir )
1311+ new_rootpath = str (pytester .path / " test")
13131312 if not os .path .exists (new_rootpath ):
13141313 os .mkdir (new_rootpath )
1315- monkeypatch .chdir (new_rootpath )
1314+ monkeypatch .setattr (config ,"invocation_params" , Config .InvocationParams (
1315+ args = (),
1316+ plugins = (),
1317+ dir = Path (new_rootpath ),
1318+ ))
13161319 state = AssertionState (config , "rewrite" )
13171320 assert state .rootpath == new_rootpath
13181321
@@ -1322,20 +1325,6 @@ def test_rootpath_base(self, pytester: Pytester, monkeypatch: MonkeyPatch) -> No
13221325 @pytest .mark .skipif (
13231326 sys .platform .startswith ("sunos5" ), reason = "cannot remove cwd on Solaris"
13241327 )
1325- def test_rootpath_cwd_removed (
1326- self , pytester : Pytester , monkeypatch : MonkeyPatch
1327- ) -> None :
1328- # Setup conditions for py's trying to os.getcwd() on py34
1329- # when current working directory doesn't exist (previously triggered via xdist only).
1330- # Ref: https://github.com/pytest-dev/py/pull/207
1331- from _pytest .assertion import AssertionState
1332-
1333- config = pytester .parseconfig ()
1334- monkeypatch .setattr (
1335- target = os , name = "getcwd" , value = Mock (side_effect = FileNotFoundError )
1336- )
1337- state = AssertionState (config , "rewrite" )
1338- assert state .rootpath == os .path .abspath (os .sep )
13391328
13401329 def test_write_pyc (self , pytester : Pytester , tmp_path ) -> None :
13411330 from _pytest .assertion import AssertionState
@@ -2034,7 +2023,11 @@ def test_simple_failure():
20342023 rootpath = f"{ os .getcwd ()} /tests"
20352024 if not os .path .exists (rootpath ):
20362025 mkdir (rootpath )
2037- monkeypatch .chdir (rootpath )
2026+ monkeypatch .setattr (pytester ._request .config ,"invocation_params" , Config .InvocationParams (
2027+ args = (),
2028+ plugins = (),
2029+ dir = Path (rootpath ),
2030+ ))
20382031 with mock .patch .object (hook , "fnpats" , ["*.py" ]):
20392032 assert hook .find_spec ("file" ) is None
20402033
@@ -2055,8 +2048,11 @@ def fix(): return 1
20552048 rootpath = f"{ os .getcwd ()} /tests"
20562049 if not os .path .exists (rootpath ):
20572050 mkdir (rootpath )
2058- monkeypatch .chdir (rootpath )
2059-
2051+ monkeypatch .setattr (pytester ._request .config ,"invocation_params" , Config .InvocationParams (
2052+ args = (),
2053+ plugins = (),
2054+ dir = Path (rootpath ),
2055+ ))
20602056 with mock .patch .object (hook , "fnpats" , ["*.py" ]):
20612057 assert hook .find_spec ("conftest" ) is not None
20622058
@@ -2080,7 +2076,11 @@ def test_assert_rewrite_correct_for_plugins(
20802076 rootpath = f"{ os .getcwd ()} /tests"
20812077 if not os .path .exists (rootpath ):
20822078 mkdir (rootpath )
2083- monkeypatch .chdir (rootpath )
2079+ monkeypatch .setattr (pytester ._request .config ,"invocation_params" , Config .InvocationParams (
2080+ args = (),
2081+ plugins = (),
2082+ dir = Path (rootpath ),
2083+ ))
20842084 with mock .patch .object (hook , "fnpats" , ["*.py" ]):
20852085 assert hook .find_spec ("plugin" ) is not None
20862086
0 commit comments