@@ -1974,11 +1974,11 @@ def test_simple_failure():
1974
1974
assert self .find_spec_calls == ["file" ]
1975
1975
1976
1976
1977
- def test_assert_excluded_rootpath (
1977
+ def test_assert_rewrites_only_rootpath (
1978
1978
self , pytester : Pytester , hook : AssertionRewritingHook , monkeypatch
1979
1979
) -> None :
1980
1980
"""
1981
- If test files contained outside rootdir , then skip them
1981
+ If test files contained outside the rootpath , then skip them
1982
1982
"""
1983
1983
pytester .makepyfile (
1984
1984
** {
@@ -1990,22 +1990,58 @@ def test_simple_failure():
1990
1990
)
1991
1991
with mock .patch .object (hook , "fnpats" , ["*.py" ]):
1992
1992
assert hook .find_spec ("file" ) is not None
1993
- root_path = f"{ os .getcwd ()} /tests"
1994
1993
1995
- if not os .path .exists (root_path ):
1996
- mkdir (root_path )
1997
- monkeypatch .chdir (root_path )
1994
+ rootpath = f"{ os .getcwd ()} /tests"
1995
+ if not os .path .exists (rootpath ):
1996
+ mkdir (rootpath )
1997
+ monkeypatch .chdir (rootpath )
1998
1998
with mock .patch .object (hook , "fnpats" , ["*.py" ]):
1999
1999
assert hook .find_spec ("file" ) is None
2000
2000
2001
2001
2002
+ def test_assert_correct_for_conftfest (
2003
+ self , pytester : Pytester , hook : AssertionRewritingHook , monkeypatch
2004
+ ) -> None :
2005
+ """
2006
+ Conftest is always rewritten regardless of the working dir
2007
+ """
2008
+ pytester .makeconftest (
2009
+ """
2010
+ import pytest
2011
+ @pytest.fixture
2012
+ def fix(): return 1
2013
+ """
2014
+ )
2015
+
2016
+ rootpath = f"{ os .getcwd ()} /tests"
2017
+ if not os .path .exists (rootpath ):
2018
+ mkdir (rootpath )
2019
+ monkeypatch .chdir (rootpath )
2020
+
2021
+ with mock .patch .object (hook , "fnpats" , ["*.py" ]):
2022
+ assert hook .find_spec ("conftest" ) is not None
2023
+
2024
+
2002
2025
def test_assert_excluded_rewrite_for_plugins (
2003
2026
self , pytester : Pytester , hook : AssertionRewritingHook , monkeypatch
2004
2027
) -> None :
2005
- plugins = {"ayncio" , "fnpats" , "pytest_bdd" , "django" , "mock" , "pytest_twisted" , "trio" }
2028
+ pkgdir = pytester .mkpydir ("plugin" )
2029
+ pkgdir .joinpath ("__init__.py" ).write_text (
2030
+ "import pytest\n "
2031
+ "@pytest.fixture\n "
2032
+ "def special_asserter():\n "
2033
+ " def special_assert(x, y):\n "
2034
+ " assert x == y\n "
2035
+ " return special_assert\n " ,
2036
+ encoding = "utf-8" ,
2037
+ )
2038
+ pytester .makeconftest ('pytest_plugins = ["plugin"]' )
2039
+ rootpath = f"{ os .getcwd ()} /tests"
2040
+ if not os .path .exists (rootpath ):
2041
+ mkdir (rootpath )
2042
+ monkeypatch .chdir (rootpath )
2006
2043
with mock .patch .object (hook , "fnpats" , ["*.py" ]):
2007
- for plugin in plugins :
2008
- assert hook .find_spec (plugin ) is None
2044
+ assert hook .find_spec ("plugin" ) is not None
2009
2045
2010
2046
2011
2047
@pytest .mark .skipif (
0 commit comments