diff --git a/pyproject.toml b/pyproject.toml index dddae152..6a6a583a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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! +""" 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: 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) 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 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 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 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(