From 35b4988c4ddfd78941d38f4989df266eda499726 Mon Sep 17 00:00:00 2001 From: Michael Karlen Date: Sun, 30 Oct 2022 16:49:32 +0100 Subject: [PATCH 1/3] Use `process_time` instead of just `time` for measuring test performance. I hope this removes a handful of random test fails on supposedly busy cloud runners. `thread_time` https://docs.python.org/3/library/time.html#time.thread_time could help with parallel test runs, too, but that only is available since Python 3.7. process_time is available since Python 3.3. --- tests/test_generic.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_generic.py b/tests/test_generic.py index 776e89124..4c9f94752 100644 --- a/tests/test_generic.py +++ b/tests/test_generic.py @@ -178,9 +178,9 @@ def test_readStringFromStream_performance(): Runs < 100ms on a 2019 notebook. Takes 10 seconds prior to #1350. """ stream = BytesIO(b"(" + b"".join([b"x"] * 1024 * 256) + b")") - start = time.time() + start = time.process_time() assert read_string_from_stream(stream) - end = time.time() + end = time.process_time() assert end - start < 2, test_readStringFromStream_performance.__doc__ From 138972eeef10e36ffaa89a5068e986f63958f7e8 Mon Sep 17 00:00:00 2001 From: Michael Karlen Date: Mon, 31 Oct 2022 20:00:28 +0100 Subject: [PATCH 2/3] Use `time.thread_time` due time tests due to parallel tests Simply skip on python < 3.7 --- tests/test_generic.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/tests/test_generic.py b/tests/test_generic.py index 4c9f94752..2bc79f645 100644 --- a/tests/test_generic.py +++ b/tests/test_generic.py @@ -176,12 +176,17 @@ def test_readStringFromStream_performance(): This test simulates reading an embedded base64 image of 256kb. It should be faster than a second, even on ancient machines. Runs < 100ms on a 2019 notebook. Takes 10 seconds prior to #1350. + + `time.thread_time` is available in python >= 3.7. We are running tests in + parallel in CI, and we don't want the other tests to fail this test due to + total time. So simply skip it on lower python versions. """ - stream = BytesIO(b"(" + b"".join([b"x"] * 1024 * 256) + b")") - start = time.process_time() - assert read_string_from_stream(stream) - end = time.process_time() - assert end - start < 2, test_readStringFromStream_performance.__doc__ + if getattr(time, "thread_time"): + stream = BytesIO(b"(" + b"".join([b"x"] * 1024 * 256) + b")") + start = time.thread_time() + assert read_string_from_stream(stream) + end = time.thread_time() + assert end - start < 2, test_readStringFromStream_performance.__doc__ def test_NameObject(caplog): From e73032eebf40b96afe9153ac1305bc8722a7c6ef Mon Sep 17 00:00:00 2001 From: Michael Karlen Date: Mon, 31 Oct 2022 20:05:03 +0100 Subject: [PATCH 3/3] use getattr properly --- tests/test_generic.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_generic.py b/tests/test_generic.py index 2bc79f645..cbd697e4b 100644 --- a/tests/test_generic.py +++ b/tests/test_generic.py @@ -181,7 +181,7 @@ def test_readStringFromStream_performance(): parallel in CI, and we don't want the other tests to fail this test due to total time. So simply skip it on lower python versions. """ - if getattr(time, "thread_time"): + if getattr(time, "thread_time", None): stream = BytesIO(b"(" + b"".join([b"x"] * 1024 * 256) + b")") start = time.thread_time() assert read_string_from_stream(stream)