2222from typing import cast
2323from unittest import mock
2424import zipfile
25+
2526from mock .mock import Mock
2627
2728import _pytest ._code
@@ -1282,12 +1283,12 @@ def test_meta_path():
12821283 )
12831284 assert pytester .runpytest ().ret == 0
12841285
1285-
12861286 def test_rootpath_base (self , pytester : Pytester , monkeypatch : MonkeyPatch ) -> None :
12871287 """
12881288 Base cases for get rootpath from AssertionState
12891289 """
12901290 from _pytest .assertion import AssertionState
1291+
12911292 config = pytester .parseconfig ()
12921293 monkeypatch .chdir (pytester .path )
12931294 state = AssertionState (config , "rewrite" )
@@ -1299,23 +1300,26 @@ def test_rootpath_base(self, pytester: Pytester, monkeypatch: MonkeyPatch) -> No
12991300 state = AssertionState (config , "rewrite" )
13001301 assert state .rootpath == new_rootpath
13011302
1302-
13031303 @pytest .mark .skipif (
13041304 sys .platform .startswith ("win32" ), reason = "cannot remove cwd on Windows"
13051305 )
13061306 @pytest .mark .skipif (
13071307 sys .platform .startswith ("sunos5" ), reason = "cannot remove cwd on Solaris"
13081308 )
1309- def test_rootpath_cwd_removed (self , pytester : Pytester , monkeypatch : MonkeyPatch ) -> None :
1309+ def test_rootpath_cwd_removed (
1310+ self , pytester : Pytester , monkeypatch : MonkeyPatch
1311+ ) -> None :
13101312 # Setup conditions for py's trying to os.getcwd() on py34
13111313 # when current working directory doesn't exist (previously triggered via xdist only).
13121314 # Ref: https://github.com/pytest-dev/py/pull/207
13131315 from _pytest .assertion import AssertionState
1316+
13141317 config = pytester .parseconfig ()
1315- monkeypatch .setattr (target = os , name = "getcwd" , value = Mock (side_effect = FileNotFoundError ))
1318+ monkeypatch .setattr (
1319+ target = os , name = "getcwd" , value = Mock (side_effect = FileNotFoundError )
1320+ )
13161321 state = AssertionState (config , "rewrite" )
1317- assert state .rootpath == os .path .abspath (os .sep )
1318-
1322+ assert state .rootpath == os .path .abspath (os .sep )
13191323
13201324 def test_write_pyc (self , pytester : Pytester , tmp_path ) -> None :
13211325 from _pytest .assertion import AssertionState
@@ -1920,6 +1924,7 @@ def hook(
19201924 if PathFinder.find_spec has been called.
19211925 """
19221926 import importlib .machinery
1927+
19231928 self .find_spec_calls : list [str ] = []
19241929 self .initial_paths : set [Path ] = set ()
19251930
@@ -1993,7 +1998,6 @@ def test_simple_failure():
19931998 assert hook .find_spec ("file" ) is not None
19941999 assert self .find_spec_calls == ["file" ]
19952000
1996-
19972001 def test_assert_rewrites_only_rootpath (
19982002 self , pytester : Pytester , hook : AssertionRewritingHook , monkeypatch
19992003 ) -> None :
@@ -2013,12 +2017,11 @@ def test_simple_failure():
20132017
20142018 rootpath = f"{ os .getcwd ()} /tests"
20152019 if not os .path .exists (rootpath ):
2016- mkdir (rootpath )
2020+ mkdir (rootpath )
20172021 monkeypatch .chdir (rootpath )
20182022 with mock .patch .object (hook , "fnpats" , ["*.py" ]):
20192023 assert hook .find_spec ("file" ) is None
20202024
2021-
20222025 def test_assert_rewrite_correct_for_conftfest (
20232026 self , pytester : Pytester , hook : AssertionRewritingHook , monkeypatch
20242027 ) -> None :
@@ -2035,12 +2038,11 @@ def fix(): return 1
20352038
20362039 rootpath = f"{ os .getcwd ()} /tests"
20372040 if not os .path .exists (rootpath ):
2038- mkdir (rootpath )
2041+ mkdir (rootpath )
20392042 monkeypatch .chdir (rootpath )
20402043
20412044 with mock .patch .object (hook , "fnpats" , ["*.py" ]):
20422045 assert hook .find_spec ("conftest" ) is not None
2043-
20442046
20452047 def test_assert_rewrite_correct_for_plugins (
20462048 self , pytester : Pytester , hook : AssertionRewritingHook , monkeypatch
@@ -2061,12 +2063,11 @@ def test_assert_rewrite_correct_for_plugins(
20612063 hook .mark_rewrite ("plugin" )
20622064 rootpath = f"{ os .getcwd ()} /tests"
20632065 if not os .path .exists (rootpath ):
2064- mkdir (rootpath )
2066+ mkdir (rootpath )
20652067 monkeypatch .chdir (rootpath )
20662068 with mock .patch .object (hook , "fnpats" , ["*.py" ]):
20672069 assert hook .find_spec ("plugin" ) is not None
20682070
2069-
20702071 @pytest .mark .skipif (
20712072 sys .platform .startswith ("win32" ), reason = "cannot remove cwd on Windows"
20722073 )
0 commit comments