summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFedora Python maintainers <python-devel@lists.fedoraproject.org>2020-07-15 13:22:59 (GMT)
committerPetr Viktorin <pviktori@redhat.com>2020-09-29 13:59:05 (GMT)
commitcb1585be36fb9178b46e76d95d0e992e03dadd60 (patch)
tree354f4f9a9c5209314cb4a5c14dcc9f7311727430
parenta1f0ebddfbe8f9cbbc99a5232f550be0f6bda3f9 (diff)
downloadcpython-cb1585be36fb9178b46e76d95d0e992e03dadd60.zip
cpython-cb1585be36fb9178b46e76d95d0e992e03dadd60.tar.gz
cpython-cb1585be36fb9178b46e76d95d0e992e03dadd60.tar.bz2
00132-add-rpmbuild-hooks-to-unittest.patch
00132 # Add non-standard hooks to unittest for use in the "check" phase below, when running selftests within the build: @unittest._skipInRpmBuild(reason) for tests that hang or fail intermittently within the build environment, and: @unittest._expectedFailureInRpmBuild for tests that always fail within the build environment The hooks only take effect if WITHIN_PYTHON_RPM_BUILD is set in the environment, which we set manually in the appropriate portion of the "check" phase below (and which potentially other python-* rpms could set, to reuse these unittest hooks in their own "check" phases)
-rw-r--r--Lib/unittest/__init__.py3
-rw-r--r--Lib/unittest/case.py38
2 files changed, 40 insertions, 1 deletions
diff --git a/Lib/unittest/__init__.py b/Lib/unittest/__init__.py
index a5d50af..f1068a5 100644
--- a/Lib/unittest/__init__.py
+++ b/Lib/unittest/__init__.py
@@ -57,7 +57,8 @@ __unittest = True
from .result import TestResult
from .case import (TestCase, FunctionTestCase, SkipTest, skip, skipIf,
- skipUnless, expectedFailure)
+ skipUnless, expectedFailure,
+ _skipInRpmBuild, _expectedFailureInRpmBuild)
from .suite import BaseTestSuite, TestSuite
from .loader import (TestLoader, defaultTestLoader, makeSuite, getTestCaseNames,
findTestCases)
diff --git a/Lib/unittest/case.py b/Lib/unittest/case.py
index a3f75af..96bd5a7 100644
--- a/Lib/unittest/case.py
+++ b/Lib/unittest/case.py
@@ -1,6 +1,7 @@
"""Test case implementation"""
import collections
+import os
import sys
import functools
import difflib
@@ -95,6 +96,43 @@ def expectedFailure(func):
return wrapper
+# Non-standard/downstream-only hooks for handling issues with specific test
+# cases:
+
+def _skipInRpmBuild(reason):
+ """
+ Non-standard/downstream-only decorator for marking a specific unit test
+ to be skipped when run within the %check of an rpmbuild.
+
+ Specifically, this takes effect when WITHIN_PYTHON_RPM_BUILD is set within
+ the environment, and has no effect otherwise.
+ """
+ if 'WITHIN_PYTHON_RPM_BUILD' in os.environ:
+ return skip(reason)
+ else:
+ return _id
+
+def _expectedFailureInRpmBuild(func):
+ """
+ Non-standard/downstream-only decorator for marking a specific unit test
+ as expected to fail within the %check of an rpmbuild.
+
+ Specifically, this takes effect when WITHIN_PYTHON_RPM_BUILD is set within
+ the environment, and has no effect otherwise.
+ """
+ @functools.wraps(func)
+ def wrapper(*args, **kwargs):
+ if 'WITHIN_PYTHON_RPM_BUILD' in os.environ:
+ try:
+ func(*args, **kwargs)
+ except Exception:
+ raise _ExpectedFailure(sys.exc_info())
+ raise _UnexpectedSuccess
+ else:
+ # Call directly:
+ func(*args, **kwargs)
+ return wrapper
+
class _AssertRaisesContext(object):
"""A context manager used to implement TestCase.assertRaises* methods."""