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>
This commit is contained in:
Mike Frysinger
2025-03-25 12:50:36 -04:00
committed by LUCI
parent d5087392ed
commit 8310436be0
4 changed files with 13 additions and 14 deletions

View File

@ -16,3 +16,8 @@
line-length = 80
# NB: Keep in sync with tox.ini.
target-version = ['py36', 'py37', 'py38', 'py39', 'py310', 'py311'] #, 'py312'
[tool.pytest.ini_options]
markers = """
skip_cq: Skip tests in the CQ. Should be rarely used!
"""

View File

@ -36,20 +36,7 @@ def is_ci() -> bool:
def run_pytest(argv: List[str]) -> int:
"""Returns the exit code from pytest."""
if is_ci():
# TODO(b/266734831): Find out why smoke tests fail.
# TODO(b/266734831): Find out why each superproject test takes 8m+.
tests_to_skip = (
"test_smoke_repo",
"test_smoke_git",
"test_superproject_get_superproject_invalid_branch",
"test_superproject_get_superproject_invalid_url",
)
print("WARNING: Skipping tests:", tests_to_skip)
argv = [
"-k",
" and ".join(f"not {x}" for x in tests_to_skip),
] + argv
argv = ["-m", "not skip_cq"] + argv
return pytest.main(argv)

View File

@ -21,6 +21,8 @@ import subprocess
import unittest
from unittest import mock
import pytest
import git_command
import wrapper
@ -263,6 +265,7 @@ class UserAgentUnitTest(unittest.TestCase):
m = re.match(r"^[^ ]+$", os_name)
self.assertIsNotNone(m)
@pytest.mark.skip_cq("TODO(b/266734831): Find out why this fails in CQ")
def test_smoke_repo(self):
"""Make sure repo UA returns something useful."""
ua = git_command.user_agent.repo
@ -271,6 +274,7 @@ class UserAgentUnitTest(unittest.TestCase):
m = re.match(r"^git-repo/[^ ]+ ([^ ]+) git/[^ ]+ Python/[0-9.]+", ua)
self.assertIsNotNone(m)
@pytest.mark.skip_cq("TODO(b/266734831): Find out why this fails in CQ")
def test_smoke_git(self):
"""Make sure git UA returns something useful."""
ua = git_command.user_agent.git

View File

@ -21,6 +21,7 @@ import tempfile
import unittest
from unittest import mock
import pytest
from test_manifest_xml import sort_attributes
import git_superproject
@ -145,6 +146,7 @@ class SuperprojectTestCase(unittest.TestCase):
)
self.assertIsNone(manifest.superproject)
@pytest.mark.skip_cq("TODO(b/266734831): Find out why this takes 8m+ in CQ")
def test_superproject_get_superproject_invalid_url(self):
"""Test with an invalid url."""
manifest = self.getXmlManifest(
@ -168,6 +170,7 @@ class SuperprojectTestCase(unittest.TestCase):
self.assertFalse(sync_result.success)
self.assertTrue(sync_result.fatal)
@pytest.mark.skip_cq("TODO(b/266734831): Find out why this takes 8m+ in CQ")
def test_superproject_get_superproject_invalid_branch(self):
"""Test with an invalid branch."""
manifest = self.getXmlManifest(