@@ -1956,11 +1956,11 @@ def test_simple_failure():
1956
1956
assert self .find_spec_calls == ["file" ]
1957
1957
1958
1958
1959
- def test_assert_excluded_rootpath (
1959
+ def test_assert_rewrites_only_rootpath (
1960
1960
self , pytester : Pytester , hook : AssertionRewritingHook , monkeypatch
1961
1961
) -> None :
1962
1962
"""
1963
- If test files contained outside rootdir , then skip them
1963
+ If test files contained outside the rootpath , then skip them
1964
1964
"""
1965
1965
pytester .makepyfile (
1966
1966
** {
@@ -1972,22 +1972,58 @@ def test_simple_failure():
1972
1972
)
1973
1973
with mock .patch .object (hook , "fnpats" , ["*.py" ]):
1974
1974
assert hook .find_spec ("file" ) is not None
1975
- root_path = f"{ os .getcwd ()} /tests"
1976
1975
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 )
1980
1980
with mock .patch .object (hook , "fnpats" , ["*.py" ]):
1981
1981
assert hook .find_spec ("file" ) is None
1982
1982
1983
1983
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
+
1984
2007
def test_assert_excluded_rewrite_for_plugins (
1985
2008
self , pytester : Pytester , hook : AssertionRewritingHook , monkeypatch
1986
2009
) -> 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 )
1988
2025
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
1991
2027
1992
2028
1993
2029
@pytest .mark .skipif (
0 commit comments