Skip to content

test: add option to run tests with network access#994

Merged
LalatenduMohanty merged 1 commit intopython-wheel-build:mainfrom
tiran:pytest-network
Mar 30, 2026
Merged

test: add option to run tests with network access#994
LalatenduMohanty merged 1 commit intopython-wheel-build:mainfrom
tiran:pytest-network

Conversation

@tiran
Copy link
Copy Markdown
Collaborator

@tiran tiran commented Mar 28, 2026

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.

Summary by CodeRabbit

Release Notes

  • Tests
    • Added support for selectively running network-dependent tests via a new command-line flag
    • Enhanced git integration testing to properly handle version detection in cloned repositories
    • Improved test infrastructure for conditional test execution based on network availability

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>
@tiran tiran requested a review from a team as a code owner March 28, 2026 14:13
@tiran tiran added the ci label Mar 28, 2026
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 28, 2026

📝 Walkthrough

Walkthrough

The changes implement conditional execution of network-dependent tests through a new --with-network command-line flag. A pytest marker system was introduced to label tests requiring network access, with automatic skipping logic in conftest.py. The test workflow was updated to enable this flag, setuptools-scm was added as a test dependency, and the git integration test was modified to use it for version detection.

Changes

Cohort / File(s) Summary
Workflow Configuration
.github/workflows/test.yaml
Updated unit test execution command to include --with-network flag, enabling network-dependent test behavior during CI runs.
Test Dependencies & Pytest Configuration
pyproject.toml
Added setuptools-scm to test optional dependencies and introduced [tool.pytest.ini_options] section with network marker definition for labeling network-access tests.
Test Framework Hooks
tests/conftest.py
Implemented pytest_addoption hook to register --with-network CLI flag and pytest_collection_modifyitems hook to conditionally skip tests marked with network keyword when flag is absent.
Integration Test Update
tests/test_gitutils.py
Applied @pytest.mark.network decorator to test_git_clone_real and introduced setuptools_scm_version() helper function to extract and verify package version from cloned repository.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Poem

🐰 With --with-network flag so bright,
Network tests skip or run just right,
Markers guide the tests along,
Conftest hooks keep flow so strong! 🌟

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title 'test: add option to run tests with network access' directly and clearly summarizes the main change: introducing a --with-network option for pytest to conditionally run network-dependent tests.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 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_scm produces 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 subprocess with untrusted input is a false positive here—root_dir comes from the controlled tmp_path fixture 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

📥 Commits

Reviewing files that changed from the base of the PR and between a939d01 and 4e01776.

📒 Files selected for processing (4)
  • .github/workflows/test.yaml
  • pyproject.toml
  • tests/conftest.py
  • tests/test_gitutils.py

@LalatenduMohanty
Copy link
Copy Markdown
Member

@tiran Can you please explain in the commit about why need this now i.e. what triggered you to do this change?

@LalatenduMohanty
Copy link
Copy Markdown
Member

This PR would help test #962, but I am not sure if that is your primary motivation.

@tiran
Copy link
Copy Markdown
Collaborator Author

tiran commented Mar 30, 2026

The test improvements are related to #938. I plan to use git_clone_fast in the new resolver and downloader API. I had written a test case for the function, but the test case is currently skipped.

@LalatenduMohanty LalatenduMohanty merged commit 5f5519a into python-wheel-build:main Mar 30, 2026
40 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants