From 579ecdaa650e6e5efa78fd169250dc17d99b137e Mon Sep 17 00:00:00 2001 From: Takashi Kajinami Date: Thu, 29 Aug 2024 17:57:54 +0900 Subject: [PATCH 1/2] Drop extras.safe_hasattr ... because it was removed[1]. [1] https://github.com/testing-cabal/extras/commit/304c046b05c72c5597f5b0568c08bbd585408973 --- stestr/subunit_runner/program.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/stestr/subunit_runner/program.py b/stestr/subunit_runner/program.py index c740cda..51d8703 100644 --- a/stestr/subunit_runner/program.py +++ b/stestr/subunit_runner/program.py @@ -18,8 +18,6 @@ import sys import unittest -import extras - def filter_by_ids(suite_or_case, test_ids): """Remove tests from suite_or_case where their id is not in test_ids. @@ -59,10 +57,10 @@ def filter_by_ids(suite_or_case, test_ids): than guessing how to reconstruct a new suite. """ # Compatible objects - if extras.safe_hasattr(suite_or_case, "filter_by_ids"): + if hasattr(suite_or_case, "filter_by_ids"): return suite_or_case.filter_by_ids(test_ids) # TestCase objects. - if extras.safe_hasattr(suite_or_case, "id"): + if hasattr(suite_or_case, "id"): if suite_or_case.id() in test_ids: return suite_or_case else: @@ -197,7 +195,7 @@ def __init__( self.runTests() else: runner = self._get_runner() - if extras.safe_hasattr(runner, "list"): + if hasattr(runner, "list"): try: runner.list(self.test, loader=self.testLoader) except TypeError: From 1bc376e081916cb496d585d247d47f226db27340 Mon Sep 17 00:00:00 2001 From: Takashi Kajinami Date: Thu, 29 Aug 2024 17:56:45 +0900 Subject: [PATCH 2/2] Replace extras.try_import ... because it can be easily replaced by built-in items. This allows us to remove dependency on the external library. --- requirements.txt | 1 - stestr/repository/memory.py | 5 +---- stestr/testlist.py | 13 +++++++++---- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/requirements.txt b/requirements.txt index 8e64059..91bb1f3 100644 --- a/requirements.txt +++ b/requirements.txt @@ -9,4 +9,3 @@ testtools>=2.2.0 # MIT PyYAML>=3.10.0 # MIT voluptuous>=0.8.9 # BSD License tomlkit>=0.11.6 # MIT -extras>=1.0.0 diff --git a/stestr/repository/memory.py b/stestr/repository/memory.py index 035ea09..7edcbcd 100644 --- a/stestr/repository/memory.py +++ b/stestr/repository/memory.py @@ -12,8 +12,7 @@ """In memory storage of test results.""" -from extras import try_import - +from collections import OrderedDict from io import BytesIO from operator import methodcaller @@ -22,8 +21,6 @@ from stestr.repository import abstract as repository -OrderedDict = try_import("collections.OrderedDict", dict) - class RepositoryFactory(repository.AbstractRepositoryFactory): """A factory that can initialise and open memory repositories. diff --git a/stestr/testlist.py b/stestr/testlist.py index 8259101..4e23bb7 100644 --- a/stestr/testlist.py +++ b/stestr/testlist.py @@ -14,10 +14,15 @@ import io -from extras import try_import - -bytestream_to_streamresult = try_import("subunit.ByteStreamToStreamResult") -stream_result = try_import("testtools.testresult.doubles.StreamResult") +try: + from subunit import ByteStreamToStreamResult as bytestream_to_streamresult +except ImportError: + bytestream_to_streamresult = None + +try: + from testtools.testresult.doubles import StreamResult as stream_result +except ImportError: + stream_result = None def write_list(stream, test_ids):