Skip to content

Commit

Permalink
Add UTC to datenow
Browse files Browse the repository at this point in the history
  • Loading branch information
fliiiix committed Nov 10, 2024
1 parent 2d6997e commit 705ca17
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 22 deletions.
4 changes: 2 additions & 2 deletions radish/extensions/cucumber_json_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
14 changes: 7 additions & 7 deletions radish/extensions/time_recorder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
22 changes: 11 additions & 11 deletions tests/unit/extensions/test_junit_xml_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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]

Expand All @@ -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]
Expand Down Expand Up @@ -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]
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
Copyright: MIT, Timo Furrer <[email protected]>
"""

from datetime import datetime
from datetime import datetime, UTC

import pytest
from freezegun import freeze_time
Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit 705ca17

Please sign in to comment.