-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
FIX key formating divergence when inspecting plugin dictionary. #11708
Merged
bluetech
merged 1 commit into
pytest-dev:main
from
fcharras:FIX/crash_during_conftest_collection
Jan 13, 2024
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Fixed a frustrating bug that afflicted some users with the only error being ``assert mod not in mods``. The issue was caused by the fact that ``str(Path(mod))`` and ``mod.__file__`` don't necessarily produce the same string, and was being erroneously used interchangably in some places in the code. | ||
|
||
This fix also broke the internal API of ``PytestPluginManager.consider_conftest`` by introducing a new parameter -- we mention this in case it is being used by external code, even if marked as *private*. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -98,6 +98,38 @@ 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: | ||
"""Unit test for issue #9765.""" | ||
config = pytester.parseconfig() | ||
pytester.makepyfile(**{"tests/conftest.py": ""}) | ||
|
||
conftest = pytester.path.joinpath("tests/conftest.py") | ||
conftest_upper_case = pytester.path.joinpath("TESTS/conftest.py") | ||
|
||
mod = config.pluginmanager._importconftest( | ||
conftest, | ||
importmode="prepend", | ||
rootpath=pytester.path, | ||
) | ||
plugin = config.pluginmanager.get_plugin(str(conftest)) | ||
assert plugin is mod | ||
|
||
mod_uppercase = config.pluginmanager._importconftest( | ||
conftest_upper_case, | ||
importmode="prepend", | ||
rootpath=pytester.path, | ||
) | ||
plugin_uppercase = config.pluginmanager.get_plugin(str(conftest_upper_case)) | ||
assert plugin_uppercase is mod_uppercase | ||
|
||
# No str(conftestpath) normalization so conftest should be imported | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll note that this is not the behavior we want -- we want them to be the same. But as we agreed I will add the normalization in a separate PR. |
||
# twice and modules should be different objects | ||
assert mod is not mod_uppercase | ||
|
||
def test_hook_tracing(self, _config_for_test: Config) -> None: | ||
pytestpm = _config_for_test.pluginmanager # fully initialized with plugins | ||
saveindent = [] | ||
|
@@ -368,7 +400,7 @@ def test_consider_conftest_deps( | |
pytester.makepyfile("pytest_plugins='xyz'"), root=pytester.path | ||
) | ||
with pytest.raises(ImportError): | ||
pytestpm.consider_conftest(mod) | ||
pytestpm.consider_conftest(mod, registration_name="unused") | ||
|
||
|
||
class TestPytestPluginManagerBootstrapming: | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I skipped the test for now, but I may consider doing a follow-up PR to add venv creation and activation in this test, via
python -m venv
+activate
, would you be OK with this?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
venv creation is quite heavy and slow, and the setuptools thing still remains, so I'd still prefer it skipped