diff --git a/green/config.py b/green/config.py index e544167..c938758 100644 --- a/green/config.py +++ b/green/config.py @@ -634,17 +634,14 @@ def getConfig(filepath=None): # pragma: no cover if filepaths: global files_loaded files_loaded = filepaths - # Python 3 has parser.read_file(iterator) while Python2 has - # parser.readfp(obj_with_readline) - read_func = getattr(parser, "read_file", getattr(parser, "readfp")) for filepath in filepaths: # Users are expected to put a [green] section # only if they use setup.cfg if filepath.endswith("setup.cfg"): with open(filepath) as f: - read_func(f) + parser.read_file(f) else: - read_func(ConfigFile(filepath)) + parser.read_file(ConfigFile(filepath)) return parser diff --git a/green/result.py b/green/result.py index 8061cbf..65c54a5 100644 --- a/green/result.py +++ b/green/result.py @@ -165,6 +165,8 @@ def __init__(self, stream, colors): self.stderr_errput = OrderedDict() self.stream = stream self.colors = colors + # The collectedDurations list is new in Python 3.12. + self.collectedDurations = [] def recordStdout(self, test, output): """ @@ -218,6 +220,19 @@ def displayStderr(self, test): ) del self.stderr_errput[test] + def addDuration(self, test, elapsed): + """ + Called when a test finished running, regardless of its outcome. + + New in Python 3.12. + + Args: + test: The test case corresponding to the test method. + elapsed: The time represented in seconds, including the + execution of cleanup functions. + """ + self.collectedDurations.append((str(test), elapsed)) + class ProtoTestResult(BaseTestResult): """ @@ -247,6 +262,7 @@ def __init__(self, start_callback=None, finalize_callback=None): def reinitialize(self): self.shouldStop = False + self.collectedDurations = [] self.errors = [] self.expectedFailures = [] self.failures = [] @@ -392,6 +408,7 @@ def __init__(self, args, stream): self.shouldStop = False self.testsRun = 0 # Individual lists + self.collectedDurations = [] self.errors = [] self.expectedFailures = [] self.failures = []