Blame 00132-add-rpmbuild-hooks-to-unittest.patch

a669008
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
a669008
From: David Malcolm <dmalcolm@redhat.com>
a669008
Date: Fri, 19 Jun 2020 16:54:05 +0200
a669008
Subject: [PATCH] 00132: Add rpmbuild hooks to unittest
a669008
a669008
Add non-standard hooks to unittest for use in the "check" phase, when
a669008
running selftests within the build:
a669008
  @unittest._skipInRpmBuild(reason)
a669008
for tests that hang or fail intermittently within the build environment, and:
a669008
  @unittest._expectedFailureInRpmBuild
a669008
for tests that always fail within the build environment
a669008
a669008
The hooks only take effect if WITHIN_PYTHON_RPM_BUILD is set in the
a669008
environment, which we set manually in the appropriate portion of the "check"
a669008
phase below (and which potentially other python-* rpms could set, to reuse
a669008
these unittest hooks in their own "check" phases)
a669008
a669008
Co-Authored-By: David Malcolm <dmalcolm@redhat.com>
a669008
Co-Authored-By: Bohuslav Kabrda <bkabrda@redhat.com>
a669008
Co-Authored-By: Robert Kuska <rkuska@redhat.com>
a669008
---
a669008
 Lib/unittest/__init__.py |  3 ++-
a669008
 Lib/unittest/case.py     | 17 +++++++++++++++++
a669008
 2 files changed, 19 insertions(+), 1 deletion(-)
a669008
a669008
diff --git a/Lib/unittest/__init__.py b/Lib/unittest/__init__.py
a669008
index c55d563e0c..79c4b10681 100644
a669008
--- a/Lib/unittest/__init__.py
a669008
+++ b/Lib/unittest/__init__.py
a669008
@@ -57,7 +57,8 @@ __unittest = True
a669008
 
a669008
 from .result import TestResult
a669008
 from .case import (TestCase, FunctionTestCase, SkipTest, skip, skipIf,
a669008
-                   skipUnless, expectedFailure)
a669008
+                   skipUnless, expectedFailure,
a669008
+                   _skipInRpmBuild)
a669008
 from .suite import BaseTestSuite, TestSuite
a669008
 from .loader import (TestLoader, defaultTestLoader, makeSuite, getTestCaseNames,
a669008
                      findTestCases)
a669008
diff --git a/Lib/unittest/case.py b/Lib/unittest/case.py
a669008
index f4dbc52852..f88668f766 100644
a669008
--- a/Lib/unittest/case.py
a669008
+++ b/Lib/unittest/case.py
a8ffdf3
@@ -3,6 +3,7 @@
a8ffdf3
 import sys
a8ffdf3
 import functools
a8ffdf3
 import difflib
a8ffdf3
+import os
a8ffdf3
 import logging
a8ffdf3
 import pprint
a8ffdf3
 import re
a669008
@@ -134,6 +135,22 @@ class _BaseTestCaseContext:
a669008
         msg = self.test_case._formatMessage(self.msg, standardMsg)
a8ffdf3
         raise self.test_case.failureException(msg)
a8ffdf3
 
a8ffdf3
+# Non-standard/downstream-only hooks for handling issues with specific test
a8ffdf3
+# cases:
a8ffdf3
+
a8ffdf3
+def _skipInRpmBuild(reason):
a8ffdf3
+    """
a8ffdf3
+    Non-standard/downstream-only decorator for marking a specific unit test
a8ffdf3
+    to be skipped when run within the %check of an rpmbuild.
a8ffdf3
+
a8ffdf3
+    Specifically, this takes effect when WITHIN_PYTHON_RPM_BUILD is set within
a8ffdf3
+    the environment, and has no effect otherwise.
a8ffdf3
+    """
a8ffdf3
+    if 'WITHIN_PYTHON_RPM_BUILD' in os.environ:
a8ffdf3
+        return skip(reason)
a8ffdf3
+    else:
a8ffdf3
+        return _id
a8ffdf3
+
a8ffdf3
 class _AssertRaisesBaseContext(_BaseTestCaseContext):
a8ffdf3
 
a8ffdf3
     def __init__(self, expected, test_case, expected_regex=None):