diff --git a/radish/extensions/cucumber_json_writer.py b/radish/extensions/cucumber_json_writer.py index 2c1c0476..7d0fc89e 100644 --- a/radish/extensions/cucumber_json_writer.py +++ b/radish/extensions/cucumber_json_writer.py @@ -4,7 +4,7 @@ This module provides a hook which generates a cucumber json result file at the end of the run. """ -from datetime import timedelta, datetime +from datetime import timedelta, datetime, UTC import json from radish.terrain import world @@ -44,7 +44,7 @@ def generate_ccjson(self, features, marker): if feature.starttime is not None: # feature file run not finished if feature.endtime is None: - duration += feature.starttime - datetime.utcnow() + duration += feature.starttime - datetime.now(UTC) # feature file run finished else: duration += feature.duration diff --git a/radish/extensions/time_recorder.py b/radish/extensions/time_recorder.py index 5ac4442b..7550e7b2 100644 --- a/radish/extensions/time_recorder.py +++ b/radish/extensions/time_recorder.py @@ -4,7 +4,7 @@ This module is a REQUIRED extension to record the time of Features, Scenarios and Steps """ -from datetime import datetime +from datetime import datetime, UTC from radish.hookregistry import after, before from radish.extensionregistry import extension @@ -33,34 +33,34 @@ def time_recorder_before_each_feature(self, feature): """ Sets the starttime of the feature """ - feature.starttime = datetime.utcnow() + feature.starttime = datetime.now(UTC) def time_recorder_before_each_scenario(self, scenario): """ Sets the starttime of the scenario """ - scenario.starttime = datetime.utcnow() + scenario.starttime = datetime.now(UTC) def time_recorder_before_each_step(self, step): """ Sets the starttime of the step """ - step.starttime = datetime.utcnow() + step.starttime = datetime.now(UTC) def time_recorder_after_each_feature(self, feature): """ Sets the endtime of the feature """ - feature.endtime = datetime.utcnow() + feature.endtime = datetime.now(UTC) def time_recorder_after_each_scenario(self, scenario): """ Sets the endtime of the scenario """ - scenario.endtime = datetime.utcnow() + scenario.endtime = datetime.now(UTC) def time_recorder_after_each_step(self, step): """ Sets the endtime of the step """ - step.endtime = datetime.utcnow() + step.endtime = datetime.now(UTC) diff --git a/tests/unit/extensions/test_junit_xml_writer.py b/tests/unit/extensions/test_junit_xml_writer.py index 13132207..ff2f01ac 100644 --- a/tests/unit/extensions/test_junit_xml_writer.py +++ b/tests/unit/extensions/test_junit_xml_writer.py @@ -11,7 +11,7 @@ import pytest -from datetime import datetime +from datetime import datetime, UTC from radish.terrain import world from radish.exceptions import RadishError @@ -33,8 +33,8 @@ def test_singel_feature_list(mocker): stub = mocker.patch("radish.extensions.junit_xml_writer.JUnitXMLWriter._write_xml_to_disk") first_feature = Feature(1, "Feature", "I am a feature", "foo.feature", 1, tags=None) - first_feature.starttime = datetime.utcnow() - first_feature.endtime = datetime.utcnow() + first_feature.starttime = datetime.now(UTC) + first_feature.endtime = datetime.now(UTC) features = [first_feature] @@ -61,12 +61,12 @@ def test_normal_feature_list(mocker): preconditions=None, background=None, ) - first_scenario.starttime = datetime.utcnow() - first_scenario.endtime = datetime.utcnow() + first_scenario.starttime = datetime.now(UTC) + first_scenario.endtime = datetime.now(UTC) first_feature = Feature(1, "Feature", "I am a feature", "foo.feature", 1, tags=None) - first_feature.starttime = datetime.utcnow() - first_feature.endtime = datetime.utcnow() + first_feature.starttime = datetime.now(UTC) + first_feature.endtime = datetime.now(UTC) first_feature.scenarios.append(first_scenario) features = [first_feature] @@ -95,12 +95,12 @@ def test_relaxed_mode_adding_tags_to_junit(mocker): preconditions=None, background=None, ) - first_scenario.starttime = datetime.utcnow() - first_scenario.endtime = datetime.utcnow() + first_scenario.starttime = datetime.now(UTC) + first_scenario.endtime = datetime.now(UTC) first_feature = Feature(1, "Feature", "I am a feature", "foo.feature", 1, tags=None) - first_feature.starttime = datetime.utcnow() - first_feature.endtime = datetime.utcnow() + first_feature.starttime = datetime.now(UTC) + first_feature.endtime = datetime.now(UTC) first_feature.scenarios.append(first_scenario) features = [first_feature] diff --git a/tests/unit/test_utils.py b/tests/unit/test_utils.py index 5b80b23f..b7c71bf1 100644 --- a/tests/unit/test_utils.py +++ b/tests/unit/test_utils.py @@ -9,7 +9,7 @@ Copyright: MIT, Timo Furrer """ -from datetime import datetime +from datetime import datetime, UTC import pytest from freezegun import freeze_time @@ -46,7 +46,7 @@ def test_date_time_formatter(): Test datetime to string format """ # given - utc_dt = datetime.utcnow() + utc_dt = datetime.now(UTC) expected_datetime_string = "2015-10-21T05:29:00" actual_datetime_string = utils.format_utc_to_local_tz(utc_dt)