Skip to content
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

Replace datetime.utcnow() with datetime.now(tz=timezone.utc), as it is kind of an antipattern #2244

Merged
merged 1 commit into from Nov 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion locust/stats.py
Expand Up @@ -880,7 +880,7 @@ def stats_history(runner: "Runner") -> None:
break
if runner.state != "stopped":
r = {
"time": datetime.datetime.utcnow().strftime("%H:%M:%S"),
"time": datetime.datetime.now(tz=datetime.timezone.utc).strftime("%H:%M:%S"),
"current_rps": stats.total.current_rps or 0,
"current_fail_per_sec": stats.total.current_fail_per_sec or 0,
"response_time_percentile_95": stats.total.get_current_response_time_percentile(0.95) or 0,
Expand Down
8 changes: 3 additions & 5 deletions locust/test/util.py
Expand Up @@ -2,9 +2,7 @@
import gc
import os
import socket
import warnings

from datetime import datetime, timedelta
import datetime
from cryptography import x509
from cryptography.x509.oid import NameOID
from cryptography.hazmat.primitives import hashes
Expand Down Expand Up @@ -57,15 +55,15 @@ def create_tls_cert(hostname):
"""Generate a TLS cert and private key to serve over https"""
key = rsa.generate_private_key(public_exponent=2**16 + 1, key_size=2048, backend=default_backend())
name = x509.Name([x509.NameAttribute(NameOID.COMMON_NAME, hostname)])
now = datetime.utcnow()
now = datetime.datetime.now(tz=datetime.timezone.utc)
cert = (
x509.CertificateBuilder()
.subject_name(name)
.issuer_name(name)
.public_key(key.public_key())
.serial_number(1000)
.not_valid_before(now)
.not_valid_after(now + timedelta(days=10 * 365))
.not_valid_after(now + datetime.timedelta(days=10 * 365))
.sign(key, hashes.SHA256(), default_backend())
)
cert_pem = cert.public_bytes(encoding=serialization.Encoding.PEM)
Expand Down