test: add option to run tests with network access#994
test: add option to run tests with network access#994LalatenduMohanty merged 1 commit intopython-wheel-build:mainfrom
Conversation
The new pytest option `--with-network` enables test cases that are decoratored with `network` marker. By default, tests like `test_git_clone_real` are disabled, because they spend a non-trivial amount of time to download content from a remote server. Co-Authored-By: Claude <claude@anthropic.com> Signed-off-by: Christian Heimes <cheimes@redhat.com>
📝 WalkthroughWalkthroughThe changes implement conditional execution of network-dependent tests through a new Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
tests/test_gitutils.py (1)
17-26: Consider handling edge cases in output parsing.The helper assumes the last line contains the version, but if
setuptools_scmproduces unexpected output (e.g., warnings only, or empty output),splitlines()[-1]could fail or return an invalid version string.For a test helper this is acceptable since failures will surface as test errors, but you might consider adding a brief comment explaining the expected output format.
Note: The Ruff S603 warning about
subprocesswith untrusted input is a false positive here—root_dircomes from the controlledtmp_pathfixture and the command is hardcoded.💡 Optional: Add defensive handling
def setuptools_scm_version(root_dir: pathlib.Path) -> Version: + """Extract version from a git repository using setuptools_scm. + + Expects the last line of output to contain the version string. + """ out = subprocess.check_output( [sys.executable, "-m", "setuptools_scm"], text=True, stderr=subprocess.STDOUT, cwd=str(root_dir), ) # last line contains the version - lastline = out.strip().splitlines()[-1] + lines = out.strip().splitlines() + if not lines: + raise ValueError(f"setuptools_scm produced no output in {root_dir}") + lastline = lines[-1] return Version(lastline)🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@tests/test_gitutils.py` around lines 17 - 26, The helper setuptools_scm_version assumes the last line of subprocess.check_output contains a valid version and can crash or produce a confusing error on empty/unexpected output; update the function setuptools_scm_version to validate the subprocess output before using splitlines(): trim and split into lines, if no lines are present raise a clear RuntimeError (including the full raw output) and then parse the last line, and wrap Version(lastline) in a try/except to raise a descriptive error if parsing fails; also add a short comment noting that root_dir is controlled by tests so the Ruff S603 warning is a false positive.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@tests/test_gitutils.py`:
- Around line 17-26: The helper setuptools_scm_version assumes the last line of
subprocess.check_output contains a valid version and can crash or produce a
confusing error on empty/unexpected output; update the function
setuptools_scm_version to validate the subprocess output before using
splitlines(): trim and split into lines, if no lines are present raise a clear
RuntimeError (including the full raw output) and then parse the last line, and
wrap Version(lastline) in a try/except to raise a descriptive error if parsing
fails; also add a short comment noting that root_dir is controlled by tests so
the Ruff S603 warning is a false positive.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: cac7fee4-a6ce-4986-a715-3703852dd04c
📒 Files selected for processing (4)
.github/workflows/test.yamlpyproject.tomltests/conftest.pytests/test_gitutils.py
|
@tiran Can you please explain in the commit about why need this now i.e. what triggered you to do this change? |
|
This PR would help test #962, but I am not sure if that is your primary motivation. |
|
The test improvements are related to #938. I plan to use |
The new pytest option
--with-networkenables test cases that are decoratored withnetworkmarker. By default, tests liketest_git_clone_realare disabled, because they spend a non-trivial amount of time to download content from a remote server.Summary by CodeRabbit
Release Notes