@@ -1956,11 +1956,11 @@ def test_simple_failure():
19561956 assert self .find_spec_calls == ["file" ]
19571957
19581958
1959- def test_assert_excluded_rootpath (
1959+ def test_assert_rewrites_only_rootpath (
19601960 self , pytester : Pytester , hook : AssertionRewritingHook , monkeypatch
19611961 ) -> None :
19621962 """
1963- If test files contained outside rootdir , then skip them
1963+ If test files contained outside the rootpath , then skip them
19641964 """
19651965 pytester .makepyfile (
19661966 ** {
@@ -1972,22 +1972,58 @@ def test_simple_failure():
19721972 )
19731973 with mock .patch .object (hook , "fnpats" , ["*.py" ]):
19741974 assert hook .find_spec ("file" ) is not None
1975- root_path = f"{ os .getcwd ()} /tests"
19761975
1977- if not os .path .exists (root_path ):
1978- mkdir (root_path )
1979- monkeypatch .chdir (root_path )
1976+ rootpath = f"{ os .getcwd ()} /tests"
1977+ if not os .path .exists (rootpath ):
1978+ mkdir (rootpath )
1979+ monkeypatch .chdir (rootpath )
19801980 with mock .patch .object (hook , "fnpats" , ["*.py" ]):
19811981 assert hook .find_spec ("file" ) is None
19821982
19831983
1984+ def test_assert_correct_for_conftfest (
1985+ self , pytester : Pytester , hook : AssertionRewritingHook , monkeypatch
1986+ ) -> None :
1987+ """
1988+ Conftest is always rewritten regardless of the working dir
1989+ """
1990+ pytester .makeconftest (
1991+ """
1992+ import pytest
1993+ @pytest.fixture
1994+ def fix(): return 1
1995+ """
1996+ )
1997+
1998+ rootpath = f"{ os .getcwd ()} /tests"
1999+ if not os .path .exists (rootpath ):
2000+ mkdir (rootpath )
2001+ monkeypatch .chdir (rootpath )
2002+
2003+ with mock .patch .object (hook , "fnpats" , ["*.py" ]):
2004+ assert hook .find_spec ("conftest" ) is not None
2005+
2006+
19842007 def test_assert_excluded_rewrite_for_plugins (
19852008 self , pytester : Pytester , hook : AssertionRewritingHook , monkeypatch
19862009 ) -> None :
1987- plugins = {"ayncio" , "fnpats" , "pytest_bdd" , "django" , "mock" , "pytest_twisted" , "trio" }
2010+ pkgdir = pytester .mkpydir ("plugin" )
2011+ pkgdir .joinpath ("__init__.py" ).write_text (
2012+ "import pytest\n "
2013+ "@pytest.fixture\n "
2014+ "def special_asserter():\n "
2015+ " def special_assert(x, y):\n "
2016+ " assert x == y\n "
2017+ " return special_assert\n " ,
2018+ encoding = "utf-8" ,
2019+ )
2020+ pytester .makeconftest ('pytest_plugins = ["plugin"]' )
2021+ rootpath = f"{ os .getcwd ()} /tests"
2022+ if not os .path .exists (rootpath ):
2023+ mkdir (rootpath )
2024+ monkeypatch .chdir (rootpath )
19882025 with mock .patch .object (hook , "fnpats" , ["*.py" ]):
1989- for plugin in plugins :
1990- assert hook .find_spec (plugin ) is None
2026+ assert hook .find_spec ("plugin" ) is not None
19912027
19922028
19932029 @pytest .mark .skipif (
0 commit comments