Skip to content

Commit

Permalink
Merge pull request #200 from scalative/fix-python-312-warnings
Browse files Browse the repository at this point in the history
Fix python 3.12 deprecation warnings
  • Loading branch information
sjagoe authored Dec 6, 2023
2 parents 6047af0 + 133cad0 commit c16558d
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 3 deletions.
8 changes: 8 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,16 @@
Changes since version 0.9.0
===========================

Packaging
---------

* Replace ``setup.py`` with ``pyproject.toml`` (#199).

Bugs Fixed
---------

* Fix deprecation warnings under Python 3.12 (#200).


Version 0.9.0
=============
Expand Down
25 changes: 22 additions & 3 deletions haas/result.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@
from .error_holder import ErrorHolder


if sys.version_info >= (3, 12):
from datetime import UTC

def datetime_utcnow():
return datetime.now(UTC)
else:
def datetime_utcnow():
return datetime.utcnow()


class TestCompletionStatus(Enum):
"""Enumeration to represent the status of a single test.
Expand Down Expand Up @@ -422,7 +432,7 @@ def startTest(self, test, start_time=None):
"""
if start_time is None:
start_time = datetime.utcnow()
start_time = datetime_utcnow()
self._test_timing[self._testcase_to_key(test)] = start_time
self._mirror_output = False
self._setup_stdout()
Expand Down Expand Up @@ -496,13 +506,13 @@ def _handle_result(self, test, status, exception=None, message=None):

started_time = self._test_timing.get(self._testcase_to_key(test))
if started_time is None and isinstance(test, ErrorHolder):
started_time = datetime.utcnow()
started_time = datetime_utcnow()
elif started_time is None:
raise RuntimeError(
'Missing test start! Please report this error as a bug in '
'haas.')

completion_time = datetime.utcnow()
completion_time = datetime_utcnow()
duration = TestDuration(started_time, completion_time)
result = TestResult.from_test_case(
test,
Expand Down Expand Up @@ -605,6 +615,15 @@ def addUnexpectedSuccess(self, test):
test, TestCompletionStatus.unexpected_success)
self.unexpectedSuccesses.append(result)

def addDuration(self, test, elapsed):
"""Called when a test finished to run, regardless of its outcome.
*test* is the test case corresponding to the test method.
*elapsed* is the time represented in seconds, and it includes the
execution of cleanup functions.
"""
# haas already handles measuring test duration. This method is
# to silence warnings under Python 3.12

def wasSuccessful(self):
"""Return ``True`` if the run was successful.
Expand Down
3 changes: 3 additions & 0 deletions haas/tests/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,6 @@ def utcnow(self):
return next(self.ret)
except StopIteration:
raise ValueError('No more mock values!')

def now(self, tz):
return self.utcnow()

0 comments on commit c16558d

Please sign in to comment.