summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMike Frysinger <vapier@google.com>2025-03-25 12:50:36 -0400
committerLUCI <gerrit-scoped@luci-project-accounts.iam.gserviceaccount.com>2025-03-25 11:19:49 -0700
commit8310436be083f8268bf8325bb2ffb65e9e178f6f (patch)
tree1aa0a97aee95407b7bdcca89df0fc57361900b36
parentd5087392edcee3c0da4ba19efb6005efd9ccf706 (diff)
downloadgit-repo-8310436be083f8268bf8325bb2ffb65e9e178f6f.tar.gz
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 <vapier@google.com> Reviewed-by: Gavin Mak <gavinmak@google.com> Commit-Queue: Mike Frysinger <vapier@google.com>
-rw-r--r--pyproject.toml5
-rwxr-xr-xrun_tests15
-rw-r--r--tests/test_git_command.py4
-rw-r--r--tests/test_git_superproject.py3
4 files changed, 13 insertions, 14 deletions
diff --git a/pyproject.toml b/pyproject.toml
index dddae152..6a6a583a 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -16,3 +16,8 @@
16line-length = 80 16line-length = 80
17# NB: Keep in sync with tox.ini. 17# NB: Keep in sync with tox.ini.
18target-version = ['py36', 'py37', 'py38', 'py39', 'py310', 'py311'] #, 'py312' 18target-version = ['py36', 'py37', 'py38', 'py39', 'py310', 'py311'] #, 'py312'
19
20[tool.pytest.ini_options]
21markers = """
22 skip_cq: Skip tests in the CQ. Should be rarely used!
23"""
diff --git a/run_tests b/run_tests
index bdf383eb..20dad8da 100755
--- a/run_tests
+++ b/run_tests
@@ -36,20 +36,7 @@ def is_ci() -> bool:
36def run_pytest(argv: List[str]) -> int: 36def run_pytest(argv: List[str]) -> int:
37 """Returns the exit code from pytest.""" 37 """Returns the exit code from pytest."""
38 if is_ci(): 38 if is_ci():
39 # TODO(b/266734831): Find out why smoke tests fail. 39 argv = ["-m", "not skip_cq"] + argv
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
53 40
54 return pytest.main(argv) 41 return pytest.main(argv)
55 42
diff --git a/tests/test_git_command.py b/tests/test_git_command.py
index ffee023b..16494499 100644
--- a/tests/test_git_command.py
+++ b/tests/test_git_command.py
@@ -21,6 +21,8 @@ import subprocess
21import unittest 21import unittest
22from unittest import mock 22from unittest import mock
23 23
24import pytest
25
24import git_command 26import git_command
25import wrapper 27import wrapper
26 28
@@ -263,6 +265,7 @@ class UserAgentUnitTest(unittest.TestCase):
263 m = re.match(r"^[^ ]+$", os_name) 265 m = re.match(r"^[^ ]+$", os_name)
264 self.assertIsNotNone(m) 266 self.assertIsNotNone(m)
265 267
268 @pytest.mark.skip_cq("TODO(b/266734831): Find out why this fails in CQ")
266 def test_smoke_repo(self): 269 def test_smoke_repo(self):
267 """Make sure repo UA returns something useful.""" 270 """Make sure repo UA returns something useful."""
268 ua = git_command.user_agent.repo 271 ua = git_command.user_agent.repo
@@ -271,6 +274,7 @@ class UserAgentUnitTest(unittest.TestCase):
271 m = re.match(r"^git-repo/[^ ]+ ([^ ]+) git/[^ ]+ Python/[0-9.]+", ua) 274 m = re.match(r"^git-repo/[^ ]+ ([^ ]+) git/[^ ]+ Python/[0-9.]+", ua)
272 self.assertIsNotNone(m) 275 self.assertIsNotNone(m)
273 276
277 @pytest.mark.skip_cq("TODO(b/266734831): Find out why this fails in CQ")
274 def test_smoke_git(self): 278 def test_smoke_git(self):
275 """Make sure git UA returns something useful.""" 279 """Make sure git UA returns something useful."""
276 ua = git_command.user_agent.git 280 ua = git_command.user_agent.git
diff --git a/tests/test_git_superproject.py b/tests/test_git_superproject.py
index 4e66521b..3ceb9320 100644
--- a/tests/test_git_superproject.py
+++ b/tests/test_git_superproject.py
@@ -21,6 +21,7 @@ import tempfile
21import unittest 21import unittest
22from unittest import mock 22from unittest import mock
23 23
24import pytest
24from test_manifest_xml import sort_attributes 25from test_manifest_xml import sort_attributes
25 26
26import git_superproject 27import git_superproject
@@ -145,6 +146,7 @@ class SuperprojectTestCase(unittest.TestCase):
145 ) 146 )
146 self.assertIsNone(manifest.superproject) 147 self.assertIsNone(manifest.superproject)
147 148
149 @pytest.mark.skip_cq("TODO(b/266734831): Find out why this takes 8m+ in CQ")
148 def test_superproject_get_superproject_invalid_url(self): 150 def test_superproject_get_superproject_invalid_url(self):
149 """Test with an invalid url.""" 151 """Test with an invalid url."""
150 manifest = self.getXmlManifest( 152 manifest = self.getXmlManifest(
@@ -168,6 +170,7 @@ class SuperprojectTestCase(unittest.TestCase):
168 self.assertFalse(sync_result.success) 170 self.assertFalse(sync_result.success)
169 self.assertTrue(sync_result.fatal) 171 self.assertTrue(sync_result.fatal)
170 172
173 @pytest.mark.skip_cq("TODO(b/266734831): Find out why this takes 8m+ in CQ")
171 def test_superproject_get_superproject_invalid_branch(self): 174 def test_superproject_get_superproject_invalid_branch(self):
172 """Test with an invalid branch.""" 175 """Test with an invalid branch."""
173 manifest = self.getXmlManifest( 176 manifest = self.getXmlManifest(