Skip to content

replace deprecated datetime.utcnow() functionality #72

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions pytest_nunit/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,8 @@ def record_testreport(self, testreport):
"outcome": "",
}
self.nunit_xml.idrefindex += 1 # Inc. node id ref counter
r["start"] = datetime.utcnow() # Will be overridden if called
r["stop"] = datetime.utcnow() # Will be overridden if called
r["start"] = datetime.now(datetime.UTC) # Will be overridden if called
r["stop"] = datetime.now(datetime.UTC) # Will be overridden if called
r["duration"] = 0 # Updated on teardown
if testreport.outcome == "skipped":
log.debug("skipping : {0}".format(testreport.longrepr))
Expand All @@ -177,7 +177,7 @@ def record_testreport(self, testreport):
r["stack-trace"] = self.nunit_xml._getcrashline(testreport)
elif testreport.when == "teardown":
r = self.nunit_xml.cases[testreport.nodeid]
r["stop"] = datetime.utcnow()
r["stop"] = datetime.now(datetime.UTC)
r["duration"] = (
(r["stop"] - r["start"]).total_seconds() if r["call-report"] else 0
) # skipped.
Expand Down Expand Up @@ -335,7 +335,7 @@ def pytest_internalerror(self, excrepr):

def pytest_sessionstart(self, *args):
"""Mark test session start time."""
self.suite_start_time = datetime.utcnow()
self.suite_start_time = datetime.now(datetime.UTC)

def _getcrashline(self, rep):
try:
Expand Down Expand Up @@ -396,7 +396,7 @@ def pytest_sessionfinish(self, session, *args):
dirname = os.path.dirname(os.path.abspath(self.logfile))
if not os.path.isdir(dirname):
os.makedirs(dirname)
self.suite_stop_time = datetime.utcnow()
self.suite_stop_time = datetime.now(datetime.UTC)
self.suite_time_delta = (
self.suite_stop_time - self.suite_start_time
).total_seconds()
Expand Down