Skip to content

Commit cb10d13

Browse files
Byroncodex
andcommitted
test: mark network-dependent tests for restricted builders
<!-- aent --> SUSE and openSUSE package builders disable network access for reproducible builds. Allow them to exclude network-using tests with `pytest -m 'not net'` while retaining local filesystem tests. Register `net` in `pyproject.toml` and document in `CONTRIBUTING.md` that it includes loopback sockets and fixture-triggered package downloads, not just internet access. Mark the daemon-based repository tests, stalled remote timeout cases, daemon restart test, installation test, and the already-skipped external clone test. Mark only the daemon-launching cleanup parameter so the other cleanup cases remain selected. Existing skips and test bodies remain unchanged. Normalize TOML formatting and imports in the touched files. Assisted-by: GPT 6.0 Astra Co-authored-by: GPT 6.0 Astra <codex@openai.com>
1 parent 2524e95 commit cb10d13

7 files changed

Lines changed: 64 additions & 57 deletions

File tree

‎CONTRIBUTING.md‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,17 @@ Deletions and renames that exercise library behavior or prepare a fixture for
7777
reuse must remain strict. If a cached fixture cannot be cleaned up, rebuild it
7878
at a fresh location before handing it to another test.
7979

80+
## Network-dependent tests
81+
82+
Mark tests that use the network with `pytest.mark.net`, including tests whose
83+
fixtures start a local Git daemon or download packages. This includes binding,
84+
listening on, and connecting to loopback sockets, not just internet access.
85+
Network-restricted package builders, such as SUSE and openSUSE build servers, can
86+
exclude these tests with `pytest -m 'not net'` after installing test dependencies.
87+
If only some parameters use the network, mark those with
88+
`pytest.param(..., marks=pytest.mark.net)` so the other cases still run. Local
89+
filesystem clones and mocked network calls do not need this marker.
90+
8091
## Fuzzing Test Specific Documentation
8192

8293
For details related to contributing to the fuzzing test suite and OSS-Fuzz integration, please

‎pyproject.toml‎

Lines changed: 20 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ build-backend = "setuptools.build_meta"
66
name = "GitPython"
77
description = "GitPython is a Python library used to interact with Git repositories"
88
authors = [
9-
{name = "Sebastian Thiel", email = "byronimo@gmail.com"},
10-
{name = "Michael Trier", email = "mtrier@gmail.com"},
9+
{ name = "Sebastian Thiel", email = "byronimo@gmail.com" },
10+
{ name = "Michael Trier", email = "mtrier@gmail.com" },
1111
]
1212
readme = "README.md"
1313
requires-python = ">=3.8"
@@ -51,10 +51,10 @@ doc = [
5151
include-package-data = true
5252

5353
[tool.setuptools.dynamic]
54-
version = {file = "VERSION"}
55-
dependencies = {file = "requirements.txt"}
56-
optional-dependencies."test" = {file = "test-requirements.txt"}
57-
optional-dependencies."gix" = {file = "gix-requirements.txt"}
54+
version = { file = "VERSION" }
55+
dependencies = { file = "requirements.txt" }
56+
optional-dependencies."test" = { file = "test-requirements.txt" }
57+
optional-dependencies."gix" = { file = "gix-requirements.txt" }
5858

5959
[tool.setuptools.packages.find]
6060
include = ["git", "git.*"]
@@ -64,7 +64,7 @@ addopts = "--cov=git --cov-report=term -rfEX"
6464
filterwarnings = "ignore::DeprecationWarning"
6565
python_files = "test_*.py"
6666
tmp_path_retention_policy = "failed"
67-
testpaths = "test" # Space separated list of paths from root e.g test tests doc/testing.
67+
testpaths = "test" # Space separated list of paths from root e.g test tests doc/testing.
6868
# --cov coverage
6969
# --cov-report term # send report to terminal term-missing -> terminal with line numbers html xml
7070
# --cov-report term-missing # to terminal with line numbers
@@ -75,8 +75,8 @@ testpaths = "test" # Space separated list of paths from root e.g test tests doc
7575
# --ignore-glob=**/gitdb/* # ignore glob paths
7676
# filterwarnings ignore::WarningType # ignores those warnings
7777
markers = [
78-
"net: tests requiring network access",
79-
]
78+
"net: tests requiring network access, including local/loopback sockets; skip with -m 'not net' on network-restricted builders",
79+
]
8080

8181
[tool.mypy]
8282
files = ["git/", "test/test_typing.py", "test/test_remote_progress.py"]
@@ -103,14 +103,8 @@ include = [
103103
"test/test_git.py",
104104
"test/test_remote_progress.py",
105105
]
106-
extraPaths = [
107-
"gitdb",
108-
"smmap",
109-
]
110-
exclude = [
111-
"gitdb",
112-
"smmap",
113-
]
106+
extraPaths = ["gitdb", "smmap"]
107+
exclude = ["gitdb", "smmap"]
114108

115109
[tool.coverage.run]
116110
source = ["git"]
@@ -122,39 +116,33 @@ omit = ["*/git/ext/*"]
122116
[tool.ruff]
123117
line-length = 120
124118
# Exclude a variety of commonly ignored directories.
125-
exclude = [
126-
"git/ext/",
127-
"gitdb/",
128-
"smmap/",
129-
"build",
130-
"dist",
131-
]
119+
exclude = ["git/ext/", "gitdb/", "smmap/", "build", "dist"]
132120
# Enable Pyflakes `E` and `F` codes by default.
133121
lint.select = [
134122
"E",
135-
"W", # See: https://pypi.org/project/pycodestyle
136-
"F", # See: https://pypi.org/project/pyflakes
123+
"W", # See: https://pypi.org/project/pycodestyle
124+
"F", # See: https://pypi.org/project/pyflakes
137125
# "I", # See: https://pypi.org/project/isort/
138126
# "S", # See: https://pypi.org/project/flake8-bandit
139127
# "UP", # See: https://docs.astral.sh/ruff/rules/#pyupgrade-up
140128
]
141129
lint.extend-select = [
142130
# "A", # See: https://pypi.org/project/flake8-builtins
143-
"B", # See: https://pypi.org/project/flake8-bugbear
144-
"C4", # See: https://pypi.org/project/flake8-comprehensions
145-
"TC004", # See: https://docs.astral.sh/ruff/rules/runtime-import-in-type-checking-block/
131+
"B", # See: https://pypi.org/project/flake8-bugbear
132+
"C4", # See: https://pypi.org/project/flake8-comprehensions
133+
"TC004", # See: https://docs.astral.sh/ruff/rules/runtime-import-in-type-checking-block/
146134
]
147135
lint.ignore = [
148136
# If it becomes necessary to ignore any rules, list them here.
149137
]
150138
lint.unfixable = [
151-
"F401", # Module imported but unused
139+
"F401", # Module imported but unused
152140
]
153141

154142
[tool.ruff.lint.per-file-ignores]
155143
"test/**" = [
156-
"B018", # useless-expression
144+
"B018", # useless-expression
157145
]
158146
"fuzzing/fuzz-targets/**" = [
159-
"E402", # environment setup must happen before the `git` module is imported, thus cannot happen at top of file
147+
"E402", # environment setup must happen before the `git` module is imported, thus cannot happen at top of file
160148
]

‎test/test_base.py‎

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,22 @@
44
# 3-Clause BSD License: https://opensource.org/license/bsd-3-clause/
55

66
import gc
7-
from io import BytesIO
87
import os.path as osp
98
import sys
9+
from io import BytesIO
1010
from unittest import skipIf
1111
from unittest.mock import patch
1212

13-
from gitdb import OInfo
14-
1513
import pytest
1614

15+
import git.objects.base as base
1716
from git import Repo
1817
from git.objects import Blob, Commit, TagObject, Tree
19-
import git.objects.base as base
2018
from git.objects.util import get_object_type_by_name
2119
from git.util import hex_to_bin
22-
23-
from test.lib import TestBase as _TestBase, with_rw_and_rw_remote_repo, with_rw_repo
20+
from gitdb import OInfo
21+
from test.lib import TestBase as _TestBase
22+
from test.lib import with_rw_and_rw_remote_repo, with_rw_repo
2423
from test.lib.fixtures import fixture_repo, writable_fixture
2524

2625

‎test/test_cleanup.py‎

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,25 @@
33

44
"""Cleanup failures must not fail, skip, or hide the result of a test."""
55

6-
from contextlib import nullcontext, suppress
76
import errno
87
import gc
98
import os
10-
from pathlib import Path
119
import socket
1210
import sys
13-
from types import SimpleNamespace
1411
import weakref
12+
from contextlib import nullcontext, suppress
13+
from pathlib import Path
14+
from types import SimpleNamespace
1515

1616
import pytest
1717

1818
from git import Repo
1919
from git.util import rmtree
2020
from test import cleanup
2121
from test.cleanup import TemporaryDirectory, cleanup_directory
22-
from test.lib import requires_symlinks, with_rw_and_rw_remote_repo, with_rw_directory, with_rw_repo
23-
from test.lib.helper import git_daemon_launched
22+
from test.lib import fixtures, requires_symlinks, with_rw_and_rw_remote_repo, with_rw_directory, with_rw_repo
2423
from test.lib.fixtures import fixture_repo, writable_fixture
25-
from test.lib import fixtures
24+
from test.lib.helper import git_daemon_launched
2625

2726

2827
@pytest.fixture
@@ -183,6 +182,7 @@ def source_repo():
183182
yield repo
184183

185184

185+
@pytest.mark.net
186186
def test_git_daemon_releases_port_and_can_restart(tmp_path):
187187
with socket.socket() as listener:
188188
listener.bind(("127.0.0.1", 0))
@@ -202,7 +202,14 @@ def test_git_daemon_releases_port_and_can_restart(tmp_path):
202202
pass
203203

204204

205-
@pytest.mark.parametrize("decorator", [with_rw_directory, with_rw_repo("HEAD"), with_rw_and_rw_remote_repo("HEAD")])
205+
@pytest.mark.parametrize(
206+
"decorator",
207+
[
208+
with_rw_directory,
209+
with_rw_repo("HEAD"),
210+
pytest.param(with_rw_and_rw_remote_repo("HEAD"), marks=pytest.mark.net),
211+
],
212+
)
206213
def test_decorators_preserve_success_with_locked_cleanup(source_repo, tmp_path, monkeypatch, locked_file, decorator):
207214
monkeypatch.setattr(cleanup.tempfile, "tempdir", str(tmp_path))
208215
directories = []

‎test/test_clone.py‎

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,18 @@
44
import os
55
import os.path as osp
66
import pathlib
7+
import re
78
import sys
8-
from unittest import skip
9-
from unittest import mock
9+
from pathlib import Path
10+
from unittest import mock, skip
11+
12+
import pytest
1013

14+
import git
1115
from git import Git, GitCommandError, Repo
1216
from git.exc import UnsafeOptionError, UnsafeProtocolError
13-
17+
from test.lib import PathLikeMock, TestBase, with_rw_directory, with_rw_repo
1418
from test.lib.fixtures import writable_fixture
15-
from test.lib import TestBase, with_rw_directory, with_rw_repo, PathLikeMock
16-
17-
from pathlib import Path
18-
import re
19-
20-
import git
21-
import pytest
2219

2320

2421
@pytest.fixture
@@ -145,6 +142,7 @@ def test_clone_from_with_path_contains_unicode(self):
145142
except UnicodeEncodeError:
146143
self.fail("Raised UnicodeEncodeError")
147144

145+
@pytest.mark.net
148146
@with_rw_directory
149147
@skip(
150148
"""The referenced repository was removed, and one needs to set up a new

‎test/test_installation.py‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,15 @@
77
import subprocess
88
import sys
99

10+
import pytest
11+
1012
from git import __version__, _backend
1113
from test.lib import TestCase, requires_symlinks
1214
from test.lib.fixtures import ROOT, writable_fixture
1315

1416

1517
class TestInstallation(TestCase):
18+
@pytest.mark.net
1619
@requires_symlinks
1720
def test_installation(self):
1821
# Virtualenv executables and its source symlink need their final location.

‎test/test_remote.py‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66
import gc
77
import os
88
import os.path as osp
9-
from pathlib import Path
109
import random
1110
import socket
1211
import sys
1312
import tempfile
1413
import threading
1514
import time
15+
from pathlib import Path
1616
from unittest import mock, skipIf
1717

1818
import pytest
@@ -34,14 +34,14 @@
3434
from git.exc import UnsafeOptionError, UnsafeProtocolError
3535
from git.util import IterableList
3636
from test.cleanup import cleanup_directory
37-
from test.lib.fixtures import fixture_repo, writable_fixture
3837
from test.lib import (
3938
GIT_DAEMON_PORT,
4039
TestBase,
4140
fixture,
4241
with_rw_and_rw_remote_repo,
4342
with_rw_repo,
4443
)
44+
from test.lib.fixtures import fixture_repo, writable_fixture
4545

4646
# Make sure we have repeatable results.
4747
random.seed(0)
@@ -1050,6 +1050,7 @@ def test_fetch_unsafe_branch_name(self, rw_repo, remote_repo):
10501050
Head.delete(remote_repo, bad_branch_name)
10511051

10521052

1053+
@pytest.mark.net
10531054
@pytest.mark.skipif(sys.platform == "win32", reason="kill_after_timeout is not supported on Windows")
10541055
@pytest.mark.parametrize("protocol", ["git", "http", "https"])
10551056
@pytest.mark.parametrize("operation", ["fetch", "pull", "push"])

0 commit comments

Comments
 (0)