@@ -1308,13 +1308,16 @@ def test_rootpath_base(self, pytester: Pytester, monkeypatch: MonkeyPatch) -> No
13081308 from _pytest .assertion import AssertionState
13091309
13101310 config = pytester .parseconfig ()
1311- monkeypatch .chdir (pytester .path )
13121311 state = AssertionState (config , "rewrite" )
1313- assert state .rootpath == str (pytester . path )
1314- new_rootpath = str (pytester .path ) + "/ test"
1312+ assert state .rootpath == str (config . invocation_params . dir )
1313+ new_rootpath = str (pytester .path / " test")
13151314 if not os .path .exists (new_rootpath ):
13161315 os .mkdir (new_rootpath )
1317- monkeypatch .chdir (new_rootpath )
1316+ monkeypatch .setattr (config ,"invocation_params" , Config .InvocationParams (
1317+ args = (),
1318+ plugins = (),
1319+ dir = Path (new_rootpath ),
1320+ ))
13181321 state = AssertionState (config , "rewrite" )
13191322 assert state .rootpath == new_rootpath
13201323
@@ -1324,20 +1327,6 @@ def test_rootpath_base(self, pytester: Pytester, monkeypatch: MonkeyPatch) -> No
13241327 @pytest .mark .skipif (
13251328 sys .platform .startswith ("sunos5" ), reason = "cannot remove cwd on Solaris"
13261329 )
1327- def test_rootpath_cwd_removed (
1328- self , pytester : Pytester , monkeypatch : MonkeyPatch
1329- ) -> None :
1330- # Setup conditions for py's trying to os.getcwd() on py34
1331- # when current working directory doesn't exist (previously triggered via xdist only).
1332- # Ref: https://github.com/pytest-dev/py/pull/207
1333- from _pytest .assertion import AssertionState
1334-
1335- config = pytester .parseconfig ()
1336- monkeypatch .setattr (
1337- target = os , name = "getcwd" , value = Mock (side_effect = FileNotFoundError )
1338- )
1339- state = AssertionState (config , "rewrite" )
1340- assert state .rootpath == os .path .abspath (os .sep )
13411330
13421331 def test_write_pyc (self , pytester : Pytester , tmp_path ) -> None :
13431332 from _pytest .assertion import AssertionState
@@ -2036,7 +2025,11 @@ def test_simple_failure():
20362025 rootpath = f"{ os .getcwd ()} /tests"
20372026 if not os .path .exists (rootpath ):
20382027 mkdir (rootpath )
2039- monkeypatch .chdir (rootpath )
2028+ monkeypatch .setattr (pytester ._request .config ,"invocation_params" , Config .InvocationParams (
2029+ args = (),
2030+ plugins = (),
2031+ dir = Path (rootpath ),
2032+ ))
20402033 with mock .patch .object (hook , "fnpats" , ["*.py" ]):
20412034 assert hook .find_spec ("file" ) is None
20422035
@@ -2057,8 +2050,15 @@ def fix(): return 1
20572050 rootpath = f"{ os .getcwd ()} /tests"
20582051 if not os .path .exists (rootpath ):
20592052 mkdir (rootpath )
2060- monkeypatch .chdir (rootpath )
2061-
2053+ monkeypatch .setattr (
2054+ pytester ._request .config ,
2055+ "invocation_params" ,
2056+ Config .InvocationParams (
2057+ args = (),
2058+ plugins = (),
2059+ dir = Path (rootpath ),
2060+ )
2061+ )
20622062 with mock .patch .object (hook , "fnpats" , ["*.py" ]):
20632063 assert hook .find_spec ("conftest" ) is not None
20642064
@@ -2082,7 +2082,15 @@ def test_assert_rewrite_correct_for_plugins(
20822082 rootpath = f"{ os .getcwd ()} /tests"
20832083 if not os .path .exists (rootpath ):
20842084 mkdir (rootpath )
2085- monkeypatch .chdir (rootpath )
2085+ monkeypatch .setattr (
2086+ pytester ._request .config ,
2087+ "invocation_params" ,
2088+ Config .InvocationParams (
2089+ args = (),
2090+ plugins = (),
2091+ dir = Path (rootpath ),
2092+ )
2093+ )
20862094 with mock .patch .object (hook , "fnpats" , ["*.py" ]):
20872095 assert hook .find_spec ("plugin" ) is not None
20882096
0 commit comments