Skip to content

Commit 8310436

Browse files
vapierLUCI
authored andcommitted
run_tests: move test filtering to pytest markers
Move the test disable logic even closer to the exact test that's disabled. This way people updating tests have a better chance of seeing they'll get reduced coverage in the CQ. Change-Id: I57c1a073a844019798b27e14d742fd32925d9ae8 Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/462882 Tested-by: Mike Frysinger <[email protected]> Reviewed-by: Gavin Mak <[email protected]> Commit-Queue: Mike Frysinger <[email protected]>
1 parent d508739 commit 8310436

File tree

4 files changed

+13
-14
lines changed

4 files changed

+13
-14
lines changed

pyproject.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,8 @@
1616
line-length = 80
1717
# NB: Keep in sync with tox.ini.
1818
target-version = ['py36', 'py37', 'py38', 'py39', 'py310', 'py311'] #, 'py312'
19+
20+
[tool.pytest.ini_options]
21+
markers = """
22+
skip_cq: Skip tests in the CQ. Should be rarely used!
23+
"""

run_tests

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -36,20 +36,7 @@ def is_ci() -> bool:
3636
def run_pytest(argv: List[str]) -> int:
3737
"""Returns the exit code from pytest."""
3838
if is_ci():
39-
# TODO(b/266734831): Find out why smoke tests fail.
40-
# TODO(b/266734831): Find out why each superproject test takes 8m+.
41-
tests_to_skip = (
42-
"test_smoke_repo",
43-
"test_smoke_git",
44-
"test_superproject_get_superproject_invalid_branch",
45-
"test_superproject_get_superproject_invalid_url",
46-
)
47-
48-
print("WARNING: Skipping tests:", tests_to_skip)
49-
argv = [
50-
"-k",
51-
" and ".join(f"not {x}" for x in tests_to_skip),
52-
] + argv
39+
argv = ["-m", "not skip_cq"] + argv
5340

5441
return pytest.main(argv)
5542

tests/test_git_command.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
import unittest
2222
from unittest import mock
2323

24+
import pytest
25+
2426
import git_command
2527
import wrapper
2628

@@ -263,6 +265,7 @@ def test_smoke_os(self):
263265
m = re.match(r"^[^ ]+$", os_name)
264266
self.assertIsNotNone(m)
265267

268+
@pytest.mark.skip_cq("TODO(b/266734831): Find out why this fails in CQ")
266269
def test_smoke_repo(self):
267270
"""Make sure repo UA returns something useful."""
268271
ua = git_command.user_agent.repo
@@ -271,6 +274,7 @@ def test_smoke_repo(self):
271274
m = re.match(r"^git-repo/[^ ]+ ([^ ]+) git/[^ ]+ Python/[0-9.]+", ua)
272275
self.assertIsNotNone(m)
273276

277+
@pytest.mark.skip_cq("TODO(b/266734831): Find out why this fails in CQ")
274278
def test_smoke_git(self):
275279
"""Make sure git UA returns something useful."""
276280
ua = git_command.user_agent.git

tests/test_git_superproject.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import unittest
2222
from unittest import mock
2323

24+
import pytest
2425
from test_manifest_xml import sort_attributes
2526

2627
import git_superproject
@@ -145,6 +146,7 @@ def test_superproject_get_superproject_no_superproject(self):
145146
)
146147
self.assertIsNone(manifest.superproject)
147148

149+
@pytest.mark.skip_cq("TODO(b/266734831): Find out why this takes 8m+ in CQ")
148150
def test_superproject_get_superproject_invalid_url(self):
149151
"""Test with an invalid url."""
150152
manifest = self.getXmlManifest(
@@ -168,6 +170,7 @@ def test_superproject_get_superproject_invalid_url(self):
168170
self.assertFalse(sync_result.success)
169171
self.assertTrue(sync_result.fatal)
170172

173+
@pytest.mark.skip_cq("TODO(b/266734831): Find out why this takes 8m+ in CQ")
171174
def test_superproject_get_superproject_invalid_branch(self):
172175
"""Test with an invalid branch."""
173176
manifest = self.getXmlManifest(

0 commit comments

Comments
 (0)