Skip to content

Commit cdc988a

Browse files
Allow datetime or str in test_sequential_control_messages (#1219)
Co-authored-by: Steven Silvester <[email protected]>
1 parent d6474e9 commit cdc988a

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ docs = [
5454
"trio"
5555
]
5656
test = [
57-
"pytest>=7.0",
57+
"pytest>=7.0,<8",
5858
"pytest-cov",
5959
"flaky",
6060
"ipyparallel",

tests/test_kernel.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -620,20 +620,25 @@ def test_sequential_control_messages():
620620
# Get replies
621621
replies = [get_reply(kc, msg_id, channel="control") for msg_id in msg_ids]
622622

623+
def ensure_datetime(arg):
624+
# Support arg which is a datetime or str.
625+
if isinstance(arg, str):
626+
if sys.version_info[:2] < (3, 11) and arg.endswith("Z"):
627+
# Python < 3.11 doesn't support "Z" suffix in datetime.fromisoformat,
628+
# so use alternative timezone format.
629+
# https://github.com/python/cpython/issues/80010
630+
arg = arg[:-1] + "+00:00"
631+
return datetime.fromisoformat(arg)
632+
return arg
633+
623634
# Check messages are processed in order, one at a time, and of a sensible duration.
624635
previous_end = None
625636
for reply, sleep in zip(replies, sleeps):
626-
start_str = reply["metadata"]["started"]
627-
if sys.version_info[:2] < (3, 11) and start_str.endswith("Z"):
628-
# Python < 3.11 doesn't support "Z" suffix in datetime.fromisoformat,
629-
# so use alternative timezone format.
630-
# https://github.com/python/cpython/issues/80010
631-
start_str = start_str[:-1] + "+00:00"
632-
start = datetime.fromisoformat(start_str)
633-
end = reply["header"]["date"] # Already a datetime
637+
start = ensure_datetime(reply["metadata"]["started"])
638+
end = ensure_datetime(reply["header"]["date"])
634639

635640
if previous_end is not None:
636-
assert start > previous_end
641+
assert start >= previous_end
637642
previous_end = end
638643

639644
assert end >= start + timedelta(seconds=sleep)

0 commit comments

Comments
 (0)