2222from typing import cast
2323from unittest import mock
2424import zipfile
25+
2526from mock .mock import Mock
2627
2728from _pytest .monkeypatch import MonkeyPatch
@@ -1300,12 +1301,12 @@ def test_meta_path():
13001301 )
13011302 assert pytester .runpytest ().ret == 0
13021303
1303-
13041304 def test_rootpath_base (self , pytester : Pytester , monkeypatch : MonkeyPatch ) -> None :
13051305 """
13061306 Base cases for get rootpath from AssertionState
13071307 """
13081308 from _pytest .assertion import AssertionState
1309+
13091310 config = pytester .parseconfig ()
13101311 monkeypatch .chdir (pytester .path )
13111312 state = AssertionState (config , "rewrite" )
@@ -1317,23 +1318,26 @@ def test_rootpath_base(self, pytester: Pytester, monkeypatch: MonkeyPatch) -> No
13171318 state = AssertionState (config , "rewrite" )
13181319 assert state .rootpath == new_rootpath
13191320
1320-
13211321 @pytest .mark .skipif (
13221322 sys .platform .startswith ("win32" ), reason = "cannot remove cwd on Windows"
13231323 )
13241324 @pytest .mark .skipif (
13251325 sys .platform .startswith ("sunos5" ), reason = "cannot remove cwd on Solaris"
13261326 )
1327- def test_rootpath_cwd_removed (self , pytester : Pytester , monkeypatch : MonkeyPatch ) -> None :
1327+ def test_rootpath_cwd_removed (
1328+ self , pytester : Pytester , monkeypatch : MonkeyPatch
1329+ ) -> None :
13281330 # Setup conditions for py's trying to os.getcwd() on py34
13291331 # when current working directory doesn't exist (previously triggered via xdist only).
13301332 # Ref: https://github.com/pytest-dev/py/pull/207
13311333 from _pytest .assertion import AssertionState
1334+
13321335 config = pytester .parseconfig ()
1333- monkeypatch .setattr (target = os , name = "getcwd" , value = Mock (side_effect = FileNotFoundError ))
1336+ monkeypatch .setattr (
1337+ target = os , name = "getcwd" , value = Mock (side_effect = FileNotFoundError )
1338+ )
13341339 state = AssertionState (config , "rewrite" )
1335- assert state .rootpath == os .path .abspath (os .sep )
1336-
1340+ assert state .rootpath == os .path .abspath (os .sep )
13371341
13381342 def test_write_pyc (self , pytester : Pytester , tmp_path ) -> None :
13391343 from _pytest .assertion import AssertionState
@@ -1938,6 +1942,7 @@ def hook(
19381942 if PathFinder.find_spec has been called.
19391943 """
19401944 import importlib .machinery
1945+
19411946 self .find_spec_calls : list [str ] = []
19421947 self .initial_paths : set [Path ] = set ()
19431948
@@ -2011,7 +2016,6 @@ def test_simple_failure():
20112016 assert hook .find_spec ("file" ) is not None
20122017 assert self .find_spec_calls == ["file" ]
20132018
2014-
20152019 def test_assert_rewrites_only_rootpath (
20162020 self , pytester : Pytester , hook : AssertionRewritingHook , monkeypatch
20172021 ) -> None :
@@ -2031,12 +2035,11 @@ def test_simple_failure():
20312035
20322036 rootpath = f"{ os .getcwd ()} /tests"
20332037 if not os .path .exists (rootpath ):
2034- mkdir (rootpath )
2038+ mkdir (rootpath )
20352039 monkeypatch .chdir (rootpath )
20362040 with mock .patch .object (hook , "fnpats" , ["*.py" ]):
20372041 assert hook .find_spec ("file" ) is None
20382042
2039-
20402043 def test_assert_rewrite_correct_for_conftfest (
20412044 self , pytester : Pytester , hook : AssertionRewritingHook , monkeypatch
20422045 ) -> None :
@@ -2053,12 +2056,11 @@ def fix(): return 1
20532056
20542057 rootpath = f"{ os .getcwd ()} /tests"
20552058 if not os .path .exists (rootpath ):
2056- mkdir (rootpath )
2059+ mkdir (rootpath )
20572060 monkeypatch .chdir (rootpath )
20582061
20592062 with mock .patch .object (hook , "fnpats" , ["*.py" ]):
20602063 assert hook .find_spec ("conftest" ) is not None
2061-
20622064
20632065 def test_assert_rewrite_correct_for_plugins (
20642066 self , pytester : Pytester , hook : AssertionRewritingHook , monkeypatch
@@ -2079,12 +2081,11 @@ def test_assert_rewrite_correct_for_plugins(
20792081 hook .mark_rewrite ("plugin" )
20802082 rootpath = f"{ os .getcwd ()} /tests"
20812083 if not os .path .exists (rootpath ):
2082- mkdir (rootpath )
2084+ mkdir (rootpath )
20832085 monkeypatch .chdir (rootpath )
20842086 with mock .patch .object (hook , "fnpats" , ["*.py" ]):
20852087 assert hook .find_spec ("plugin" ) is not None
20862088
2087-
20882089 @pytest .mark .skipif (
20892090 sys .platform .startswith ("win32" ), reason = "cannot remove cwd on Windows"
20902091 )
0 commit comments