From 48aa4b3af2394c76c177e90b9332ccdca39605ab Mon Sep 17 00:00:00 2001 From: Franck Charras <29153872+fcharras@users.noreply.github.com> Date: Tue, 19 Dec 2023 13:47:30 +0100 Subject: [PATCH 1/4] Add a non regression test for 9765 --- testing/test_pluginmanager.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/testing/test_pluginmanager.py b/testing/test_pluginmanager.py index e5773412fbf..b01d36d1ab2 100644 --- a/testing/test_pluginmanager.py +++ b/testing/test_pluginmanager.py @@ -98,6 +98,37 @@ def pytest_configure(self): config.pluginmanager.register(A()) assert len(values) == 2 + @pytest.mark.skipif( + not sys.platform.startswith("win"), + reason="requires a case-insensitive file system", + ) + def test_conftestpath_case_sensitivity(self, pytester: Pytester) -> None: + """Non-regression test for https://github.com/pytest-dev/pytest/issues/9765 + + Ensures that the conftests are registered in the plugin dictionary with a key + that does not depend on the case of the input path if the filesystem is + case-insensitive. + """ + + config = pytester.parseconfig() + pytester.makepyfile(**{"tests/conftest.py": ""}) + + conftest = pytester.path.joinpath("tests/conftest.py") + conftest_lower = pytester.path.joinpath("TESTS/CONFTEST.PY") + + mod = config.pluginmanager._importconftest( + conftest, importmode="prepend", rootpath=pytester.path + ) + + # Those two calls should succeed because the conftest should be registered + # independently of the casing of conftestpath. + assert mod is config.pluginmanager._importconftest( + conftest, importmode="prepend", rootpath=pytester.path + ) + assert mod is config.pluginmanager._importconftest( + conftest_lower, importmode="prepend", rootpath=pytester.path + ) + def test_hook_tracing(self, _config_for_test: Config) -> None: pytestpm = _config_for_test.pluginmanager # fully initialized with plugins saveindent = [] From 340ba5b87e85ec41520edf608a0e70b1ef35e991 Mon Sep 17 00:00:00 2001 From: Franck Charras <29153872+fcharras@users.noreply.github.com> Date: Tue, 19 Dec 2023 14:10:31 +0100 Subject: [PATCH 2/4] Try different path constructor --- testing/test_pluginmanager.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testing/test_pluginmanager.py b/testing/test_pluginmanager.py index b01d36d1ab2..4af31d14350 100644 --- a/testing/test_pluginmanager.py +++ b/testing/test_pluginmanager.py @@ -114,7 +114,7 @@ def test_conftestpath_case_sensitivity(self, pytester: Pytester) -> None: pytester.makepyfile(**{"tests/conftest.py": ""}) conftest = pytester.path.joinpath("tests/conftest.py") - conftest_lower = pytester.path.joinpath("TESTS/CONFTEST.PY") + conftest_lower = type(conftest)("TESTS/CONFTEST.PY") mod = config.pluginmanager._importconftest( conftest, importmode="prepend", rootpath=pytester.path From 901d3d46ba6a557fcd779f8aff185b29f7ccec1b Mon Sep 17 00:00:00 2001 From: Franck Charras <29153872+fcharras@users.noreply.github.com> Date: Tue, 19 Dec 2023 14:20:22 +0100 Subject: [PATCH 3/4] Lower conftest.py --- testing/test_pluginmanager.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testing/test_pluginmanager.py b/testing/test_pluginmanager.py index 4af31d14350..72ec5d09c3c 100644 --- a/testing/test_pluginmanager.py +++ b/testing/test_pluginmanager.py @@ -114,7 +114,7 @@ def test_conftestpath_case_sensitivity(self, pytester: Pytester) -> None: pytester.makepyfile(**{"tests/conftest.py": ""}) conftest = pytester.path.joinpath("tests/conftest.py") - conftest_lower = type(conftest)("TESTS/CONFTEST.PY") + conftest_lower = pytester.path.joinpath("TESTS/conftest.py") mod = config.pluginmanager._importconftest( conftest, importmode="prepend", rootpath=pytester.path From 2c836fa507a6a6bf06b087ba515c1c2a3d6a7528 Mon Sep 17 00:00:00 2001 From: Franck Charras <29153872+fcharras@users.noreply.github.com> Date: Tue, 19 Dec 2023 14:46:46 +0100 Subject: [PATCH 4/4] Adds similar test with differents paths that resolves identically --- testing/test_pluginmanager.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/testing/test_pluginmanager.py b/testing/test_pluginmanager.py index 72ec5d09c3c..ecd98f5158f 100644 --- a/testing/test_pluginmanager.py +++ b/testing/test_pluginmanager.py @@ -129,6 +129,32 @@ def test_conftestpath_case_sensitivity(self, pytester: Pytester) -> None: conftest_lower, importmode="prepend", rootpath=pytester.path ) + def test_conftestpath_no_normalization(self, pytester: Pytester) -> None: + """Non-regression test for https://github.com/pytest-dev/pytest/issues/9765 + + Ensures that the conftests are registered in the plugin dictionary with a key + that does not depend on the normalization of the input path. + """ + + config = pytester.parseconfig() + pytester.makepyfile(**{"tests/conftest.py": ""}) + + conftest = pytester.path.joinpath("tests/conftest.py") + contest_similar = pytester.path.joinpath("tests/../tests/conftest.py") + + mod = config.pluginmanager._importconftest( + conftest, importmode="prepend", rootpath=pytester.path + ) + + # Those two calls should succeed because the conftest should be registered + # independently of the normalization of conftestpath. + assert mod is config.pluginmanager._importconftest( + conftest, importmode="prepend", rootpath=pytester.path + ) + assert mod is config.pluginmanager._importconftest( + contest_similar, importmode="prepend", rootpath=pytester.path + ) + def test_hook_tracing(self, _config_for_test: Config) -> None: pytestpm = _config_for_test.pluginmanager # fully initialized with plugins saveindent = []