Skip to content

Commit 0eb62b9

Browse files
Configure some tests to run offline (#890)
1 parent 4927e0a commit 0eb62b9

9 files changed

Lines changed: 62 additions & 10 deletions

File tree

tests/usethis/_core/test_core_tool.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1018,6 +1018,7 @@ def test_small_contracts_dropped(
10181018
"""
10191019
)
10201020

1021+
@pytest.mark.usefixtures("_vary_network_conn")
10211022
def test_cyclic_excluded(self, tmp_path: Path, monkeypatch: pytest.MonkeyPatch):
10221023
# Arrange
10231024
(tmp_path / ".importlinter").touch()
@@ -1053,6 +1054,7 @@ def test_cyclic_excluded(self, tmp_path: Path, monkeypatch: pytest.MonkeyPatch):
10531054
"""
10541055
)
10551056

1057+
@pytest.mark.usefixtures("_vary_network_conn")
10561058
def test_existing_ini_match(self, tmp_path: Path):
10571059
# Arrange
10581060
(tmp_path / ".importlinter").write_text(
@@ -1081,6 +1083,7 @@ def test_existing_ini_match(self, tmp_path: Path):
10811083
"""
10821084
)
10831085

1086+
@pytest.mark.usefixtures("_vary_network_conn")
10841087
def test_existing_ini_differs(self, tmp_path: Path):
10851088
# Arrange
10861089
(tmp_path / ".importlinter").write_text(
@@ -1109,6 +1112,7 @@ def test_existing_ini_differs(self, tmp_path: Path):
11091112
"""
11101113
)
11111114

1115+
@pytest.mark.usefixtures("_vary_network_conn")
11121116
def test_numbers_in_layer_names(self, tmp_path: Path):
11131117
# Arrange
11141118
(tmp_path / ".importlinter").touch()
@@ -1140,6 +1144,7 @@ def test_numbers_in_layer_names(self, tmp_path: Path):
11401144
"""
11411145
)
11421146

1147+
@pytest.mark.usefixtures("_vary_network_conn")
11431148
def test_nesting(self, tmp_path: Path):
11441149
# Arrange
11451150
(tmp_path / ".importlinter").touch()
@@ -1183,6 +1188,7 @@ def test_nesting(self, tmp_path: Path):
11831188
"""
11841189
)
11851190

1191+
@pytest.mark.usefixtures("_vary_network_conn")
11861192
def test_multiple_packages_with_nesting(self, tmp_path: Path):
11871193
# The logic here is that we want to have the minimum number of nesting
11881194
# levels required to reach the minimum number of modules which is 3.
@@ -1539,6 +1545,7 @@ def test_config(
15391545
)
15401546

15411547
class TestBitbucketIntegration:
1548+
@pytest.mark.usefixtures("_vary_network_conn")
15421549
def test_config_file(self, tmp_path: Path):
15431550
# Arrange
15441551
(tmp_path / "bitbucket-pipelines.yml").write_text("""\
@@ -1582,6 +1589,7 @@ def test_config_contents(self, tmp_path: Path):
15821589
"""
15831590
)
15841591

1592+
@pytest.mark.usefixtures("_vary_network_conn")
15851593
def test_successful_build(self, tmp_path: Path):
15861594
# Act
15871595
with change_cwd(tmp_path), files_manager():
@@ -2055,6 +2063,7 @@ def test_add_unsubsumed_tools(self, uv_init_repo_dir: Path):
20552063
assert "ruff" in contents
20562064

20572065
class TestMultipleIntegrations:
2066+
@pytest.mark.usefixtures("_vary_network_conn")
20582067
def test_hooks_run_all_tools_empty_repo(self, uv_env_dir: Path):
20592068
# Arrange
20602069
with change_cwd(uv_env_dir), files_manager():
@@ -2486,6 +2495,7 @@ def test_pyproject_without_ini_priority(self, uv_init_repo_dir: Path):
24862495
# Assert
24872496
assert (uv_init_repo_dir / "setup.cfg").read_text()
24882497

2498+
@pytest.mark.usefixtures("_vary_network_conn")
24892499
def test_pythonpath_needed(self, tmp_path: Path):
24902500
# https://github.com/usethis-python/usethis-python/issues/347
24912501

@@ -2917,6 +2927,7 @@ def test_pre_commit_first(self, uv_init_repo_dir: Path):
29172927
assert "ruff-format" in hook_names
29182928
assert "ruff" in hook_names
29192929

2930+
@pytest.mark.usefixtures("_vary_network_conn")
29202931
def test_creates_pyproject_toml(
29212932
self, tmp_path: Path, capfd: pytest.CaptureFixture[str]
29222933
):
@@ -3484,6 +3495,7 @@ def test_remove_only_linter_yaml_only(
34843495
)
34853496

34863497
class TestBitbucketIntegration:
3498+
@pytest.mark.usefixtures("_vary_network_conn")
34873499
def test_add_linter_only(self, tmp_path: Path):
34883500
# Arrange
34893501
(tmp_path / "bitbucket-pipelines.yml").write_text("""\
@@ -3500,6 +3512,7 @@ def test_add_linter_only(self, tmp_path: Path):
35003512
assert "ruff check" in contents
35013513
assert "ruff format" not in contents
35023514

3515+
@pytest.mark.usefixtures("_vary_network_conn")
35033516
def test_add_formatter_only(self, tmp_path: Path):
35043517
# Arrange
35053518
(tmp_path / "bitbucket-pipelines.yml").write_text("""\

tests/usethis/_core/test_docstyle.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ def test_pep257(self, tmp_path: Path):
8383
"""
8484
)
8585

86+
@pytest.mark.usefixtures("_vary_network_conn")
8687
def test_pyproject_toml_numpy(self, tmp_path: Path):
8788
# Also tests the case that ruff isn't used yet.
8889

@@ -170,6 +171,7 @@ def test_leave_ok_config_alone(self, tmp_path: Path):
170171
# Assert
171172
assert contents == (tmp_path / "ruff.toml").read_text()
172173

174+
@pytest.mark.usefixtures("_vary_network_conn")
173175
def test_adding_ruff_afterwards_allows_default_rules(self, tmp_path: Path):
174176
# Arrange
175177
(tmp_path / "ruff.toml").touch()

tests/usethis/_interface/test_doc.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,25 @@
11
from pathlib import Path
22

3+
import pytest
34
from typer.testing import CliRunner
45

56
from usethis._app import app
7+
from usethis._config import usethis_config
68
from usethis._config_file import files_manager
79
from usethis._integrations.uv.deps import Dependency, get_deps_from_group
810
from usethis._test import change_cwd
911

1012

1113
class TestDoc:
14+
@pytest.mark.usefixtures("_vary_network_conn")
1215
def test_dependencies_added(self, tmp_path: Path):
1316
# Act
1417
runner = CliRunner()
1518
with change_cwd(tmp_path):
16-
result = runner.invoke(app, ["doc"])
19+
if not usethis_config.offline:
20+
result = runner.invoke(app, ["doc"])
21+
else:
22+
result = runner.invoke(app, ["doc", "--offline"])
1723

1824
# Assert
1925
assert result.exit_code == 0, result.output

tests/usethis/_interface/test_docstyle.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
from pathlib import Path
22

3+
import pytest
34
from typer.testing import CliRunner
45

56
from usethis._app import app
7+
from usethis._config import usethis_config
68
from usethis._core.enums.docstyle import DocStyleEnum
79
from usethis._interface.docstyle import docstyle
810
from usethis._test import change_cwd
@@ -27,6 +29,7 @@ def test_invalid_pyproject_toml(self, tmp_path: Path):
2729
# Assert
2830
assert result.exit_code == 1, result.output
2931

32+
@pytest.mark.usefixtures("_vary_network_conn")
3033
def test_pyproject_toml_success(self, tmp_path: Path):
3134
# https://github.com/usethis-python/usethis-python/issues/507
3235

@@ -37,7 +40,10 @@ def test_pyproject_toml_success(self, tmp_path: Path):
3740
# Act
3841
with change_cwd(tmp_path):
3942
runner = CliRunner()
40-
result = runner.invoke(app, ["docstyle", "numpy"])
43+
if not usethis_config.offline:
44+
result = runner.invoke(app, ["docstyle", "numpy"])
45+
else:
46+
result = runner.invoke(app, ["docstyle", "numpy", "--offline"])
4147

4248
# Assert
4349
assert result.exit_code == 0, result.output
@@ -81,6 +87,7 @@ def test_adding_to_existing_file(self, tmp_path: Path):
8187
content = existing_pyproject_toml.read_text()
8288
assert "[lint.pydocstyle]" not in content # Wrong section name
8389

90+
@pytest.mark.usefixtures("_vary_network_conn")
8491
def test_default(self, tmp_path: Path):
8592
# Arrange
8693
default_pyproject_toml = tmp_path / "pyproject.toml"
@@ -89,7 +96,10 @@ def test_default(self, tmp_path: Path):
8996
# Act
9097
with change_cwd(tmp_path):
9198
runner = CliRunner()
92-
result = runner.invoke(app, ["docstyle"])
99+
if not usethis_config.offline:
100+
result = runner.invoke(app, ["docstyle"])
101+
else:
102+
result = runner.invoke(app, ["docstyle", "--offline"])
93103

94104
# Assert
95105
assert result.exit_code == 0, result.output

tests/usethis/_interface/test_format_.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,25 @@
11
from pathlib import Path
22

3+
import pytest
34
from typer.testing import CliRunner
45

56
from usethis._app import app
7+
from usethis._config import usethis_config
68
from usethis._config_file import files_manager
79
from usethis._integrations.uv.deps import Dependency, get_deps_from_group
810
from usethis._test import change_cwd
911

1012

1113
class TestFormat:
14+
@pytest.mark.usefixtures("_vary_network_conn")
1215
def test_dependencies_added(self, tmp_path: Path):
1316
# Act
1417
runner = CliRunner()
1518
with change_cwd(tmp_path):
16-
result = runner.invoke(app, ["format"])
19+
if not usethis_config.offline:
20+
result = runner.invoke(app, ["format"])
21+
else:
22+
result = runner.invoke(app, ["format", "--offline"])
1723

1824
# Assert
1925
assert result.exit_code == 0, result.output

tests/usethis/_interface/test_init.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,28 @@
11
from pathlib import Path
22

3+
import pytest
34
from typer.testing import CliRunner
45

56
from usethis._app import app
7+
from usethis._config import usethis_config
68
from usethis._integrations.pre_commit.hooks import get_hook_ids
79
from usethis._test import change_cwd
810

911

1012
class TestInit:
13+
@pytest.mark.usefixtures("_vary_network_conn")
1114
def test_pre_commit_included(self, tmp_path: Path):
1215
# Act
1316
runner = CliRunner()
1417
with change_cwd(tmp_path):
15-
result = runner.invoke(
16-
app, ["init", "--pre-commit"], catch_exceptions=False
17-
)
18+
if not usethis_config.offline:
19+
result = runner.invoke(
20+
app, ["init", "--pre-commit"], catch_exceptions=False
21+
)
22+
else:
23+
result = runner.invoke(
24+
app, ["init", "--pre-commit", "--offline"], catch_exceptions=False
25+
)
1826

1927
# Assert
2028
assert result.exit_code == 0, result.output

tests/usethis/_interface/test_tool.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,10 @@ def test_runs(self, tmp_path: Path):
153153
# Act
154154
runner = CliRunner()
155155
with change_cwd(tmp_path):
156-
result = runner.invoke(app, ["deptry"])
156+
if not usethis_config.offline:
157+
result = runner.invoke(app, ["deptry"])
158+
else:
159+
result = runner.invoke(app, ["deptry", "--offline"])
157160

158161
# Assert
159162
assert result.exit_code == 0, result.output

tests/usethis/_tool/impl/test_codespell.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
import pytest
55

6+
from usethis._config import usethis_config
67
from usethis._config_file import files_manager
78
from usethis._integrations.ci.github.errors import GitHubTagError
89
from usethis._integrations.ci.github.tags import get_github_latest_tag
@@ -98,6 +99,7 @@ def test_both_devdep_and_pre_commit_used(
9899
assert not err
99100
assert out == ("☐ Run 'codespell' to run the Codespell spellchecker.\n")
100101

102+
@pytest.mark.usefixtures("_vary_network_conn")
101103
def test_latest_version(self):
102104
(config,) = CodespellTool().get_pre_commit_config().repo_configs
103105
repo = config.repo
@@ -107,7 +109,7 @@ def test_latest_version(self):
107109
owner="codespell-project", repo="codespell"
108110
)
109111
except GitHubTagError as err:
110-
if os.getenv("CI"):
112+
if os.getenv("CI") or usethis_config.offline:
111113
pytest.skip(
112114
"Failed to fetch GitHub tags (connection issues); skipping test"
113115
)

tests/usethis/_tool/impl/test_pyproject_fmt.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
import pytest
55

6+
from usethis._config import usethis_config
67
from usethis._config_file import files_manager
78
from usethis._integrations.ci.github.errors import GitHubTagError
89
from usethis._integrations.ci.github.tags import get_github_latest_tag
@@ -28,6 +29,7 @@ def test_uv_only(self, tmp_path: Path, capfd: pytest.CaptureFixture[str]):
2829
"☐ Run 'uv run pyproject-fmt pyproject.toml' to run pyproject-fmt.\n"
2930
)
3031

32+
@pytest.mark.usefixtures("_vary_network_conn")
3133
def test_latest_version(self):
3234
(config,) = PyprojectFmtTool().get_pre_commit_config().repo_configs
3335
repo = config.repo
@@ -37,7 +39,7 @@ def test_latest_version(self):
3739
owner="tox-dev", repo="pyproject-fmt"
3840
)
3941
except GitHubTagError as err:
40-
if os.getenv("CI"):
42+
if os.getenv("CI") or usethis_config.offline:
4143
pytest.skip(
4244
"Failed to fetch GitHub tags (connection issues); skipping test"
4345
)

0 commit comments

Comments
 (0)