test: fix strict positional parameter enforcement under pytest#2756
Open
Capstan wants to merge 1 commit into
Open
test: fix strict positional parameter enforcement under pytest#2756Capstan wants to merge 1 commit into
Capstan wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Code Review
This pull request simplifies the test initialization in tests/__init__.py by removing the setup_package function and executing the configuration directly at the module level. The review feedback suggests using a predefined constant instead of a hardcoded string to prevent typos and improve maintainability.
Historically, `positional_parameters_enforcement = "EXCEPTION"` was set inside `setup_package()` hook in `tests/__init__.py`. However, this hook is not automatically called by modern test runners like `pytest` when running tests, causing strict positional argument validation tests to be silently bypassed. Moving this setup to the module level in `tests/__init__.py` ensures that strict positional parameter enforcement is active whenever the tests package is imported, correctly running tests under pytest with positional enforcement enabled. #jetski AI_USAGE=true
dee0648 to
19b52f9
Compare
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
This PR fixes a test suite configuration bug where strict positional parameter checking was silently bypassed when running the tests under
pytest.Problem
Historically, strict positional parameter checking was enabled during test setup by setting
util.positional_parameters_enforcement = "EXCEPTION"inside asetup_package()hook insidetests/__init__.py.However, modern test runs in this repository (including through
noxsessions) run underpytest. Unlike the legacynosetest runner,pytestdoes not automatically execute package-levelsetup_package()hooks.Because this hook was ignored:
positional_parameters_enforcementremained in its default warning-only state.TypeErrors to be thrown) were being bypassed or would fail if executed directly.Solution
util.positional_parameters_enforcement = "EXCEPTION"to the module level oftests/__init__.py. This ensures that the strict check environment is correctly initialized the momentpytestimports thetestspackage.setup_package()hook to keep the codebase clean and free of deprecated test runner baggage.Verification
Ran the strict positional test case directly using
pyteston a clean virtual environment:AssertionError(only warning log generated, no exception thrown).TypeErrorand asserts it correctly).Fixes #2755