Skip to content

Commit ac86ad0

Browse files
unittest forever (#685)
* unittest * no retry * rm that
1 parent 1f07e67 commit ac86ad0

7 files changed

Lines changed: 29 additions & 43 deletions

File tree

lefthook.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,5 @@ test:
2828
# *** tests ***
2929
test_runner:
3030
run: msgq/test_runner
31-
pytest:
32-
run: pytest
31+
unittest:
32+
run: python -m unittest discover -t . -s msgq

msgq/conftest.py

Lines changed: 0 additions & 6 deletions
This file was deleted.

msgq/tests/test_fake.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
import pytest
21
import multiprocessing
32
import platform
3+
import unittest
44
import msgq
55
from parameterized import parameterized_class
66
from typing import Optional
77

88
WAIT_TIMEOUT = 5
99

1010

11-
@pytest.mark.skipif(condition=platform.system() == "Darwin", reason="Events not supported on macOS")
12-
class TestEvents:
11+
@unittest.skipIf(platform.system() == "Darwin", "Events not supported on macOS")
12+
class TestEvents(unittest.TestCase):
1313

1414
def test_mutation(self):
1515
handle = msgq.fake_event_handle("carState")
@@ -32,7 +32,7 @@ def test_wait(self):
3232
event.wait(WAIT_TIMEOUT)
3333
assert event.peek()
3434
except RuntimeError:
35-
pytest.fail("event.wait() timed out")
35+
self.fail("event.wait() timed out")
3636

3737
def test_wait_multiprocess(self):
3838
handle = msgq.fake_event_handle("carState")
@@ -47,7 +47,7 @@ def set_event_run():
4747
event.wait(WAIT_TIMEOUT)
4848
assert event.peek()
4949
except RuntimeError:
50-
pytest.fail("event.wait() timed out")
50+
self.fail("event.wait() timed out")
5151

5252
p.kill()
5353

@@ -57,26 +57,28 @@ def test_wait_zero_timeout(self):
5757

5858
try:
5959
event.wait(0)
60-
pytest.fail("event.wait() did not time out")
60+
self.fail("event.wait() did not time out")
6161
except RuntimeError:
6262
assert not event.peek()
6363

6464

65-
@pytest.mark.skipif(condition=platform.system() == "Darwin", reason="FakeSockets not supported on macOS")
65+
@unittest.skipIf(platform.system() == "Darwin", "FakeSockets not supported on macOS")
6666
@parameterized_class([{"prefix": None}, {"prefix": "test"}])
67-
class TestFakeSockets:
67+
class TestFakeSockets(unittest.TestCase):
6868
prefix: Optional[str] = None
6969

70-
def setup_method(self):
70+
def setUp(self):
71+
super().setUp()
7172
msgq.toggle_fake_events(True)
7273
if self.prefix is not None:
7374
msgq.set_fake_prefix(self.prefix)
7475
else:
7576
msgq.delete_fake_prefix()
7677

77-
def teardown_method(self):
78+
def tearDown(self):
7879
msgq.toggle_fake_events(False)
7980
msgq.delete_fake_prefix()
81+
super().tearDown()
8082

8183
def test_event_handle_init(self):
8284
handle = msgq.fake_event_handle("controlsState", override=True)
@@ -132,7 +134,7 @@ def test_sockets_enable_disable(self):
132134
_ = sub_sock.receive()
133135
assert not recv_called.peek()
134136
except RuntimeError:
135-
pytest.fail("event.wait() timed out")
137+
self.fail("event.wait() timed out")
136138

137139
def test_synced_pub_sub(self):
138140
def daemon_repub_process_run():
@@ -181,6 +183,6 @@ def daemon_repub_process_run():
181183
frame = int.from_bytes(msg, 'little')
182184
assert frame == i
183185
except RuntimeError:
184-
pytest.fail("event.wait() timed out")
186+
self.fail("event.wait() timed out")
185187
finally:
186188
p.kill()

msgq/tests/test_messaging.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
import random
22
import time
33
import string
4+
import unittest
45
import msgq
5-
import pytest
6+
67

78
def random_sock():
89
return ''.join(random.choices(string.ascii_uppercase + string.digits, k=10))
910

1011
def random_bytes(length=1000):
1112
return bytes([random.randrange(0xFF) for _ in range(length)])
1213

13-
class TestPubSubSockets:
14+
class TestPubSubSockets(unittest.TestCase):
1415

1516
def test_pub_sub(self):
1617
sock = random_sock()
@@ -45,13 +46,14 @@ def test_conflate(self):
4546
for rec_msg, sent_msg in zip(recvd_msgs, sent_msgs):
4647
assert rec_msg == sent_msg
4748

48-
@pytest.mark.flaky(retries=3, delay=1)
4949
def test_receive_timeout(self):
5050
sock = random_sock()
51-
timeout = random.randrange(200)
52-
sub_sock = msgq.sub_sock(sock, timeout=timeout)
51+
timeout_ms = 50
52+
sub_sock = msgq.sub_sock(sock, timeout=timeout_ms)
5353

5454
start_time = time.monotonic()
5555
recvd = sub_sock.receive()
56-
assert (time.monotonic() - start_time) < (timeout + 0.1)
56+
elapsed = time.monotonic() - start_time
5757
assert recvd is None
58+
assert elapsed >= timeout_ms / 1000
59+
assert elapsed < 5 # this can be noisy due to other load on the system

msgq/tests/test_poller.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import pytest
1+
import unittest
22
import time
33
import msgq
44
import concurrent.futures
@@ -20,7 +20,7 @@ def poller():
2020
return r
2121

2222

23-
class TestPoller:
23+
class TestPoller(unittest.TestCase):
2424
def test_poll_once(self):
2525
context = msgq.Context()
2626

@@ -73,7 +73,7 @@ def test_poll_and_create_many_subscribers(self):
7373
def test_multiple_publishers_exception(self):
7474
context = msgq.Context()
7575

76-
with pytest.raises(msgq.MultiplePublishersError):
76+
with self.assertRaises(msgq.MultiplePublishersError):
7777
pub1 = msgq.PubSocket()
7878
pub1.connect(context, SERVICE_NAME)
7979

msgq/visionipc/tests/test_visionipc.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import random
2+
import unittest
23
from typing import Optional
34
import numpy as np
45
from msgq.visionipc import VisionIpcServer, VisionIpcClient, VisionStreamType
56

67

7-
class TestVisionIpc:
8+
class TestVisionIpc(unittest.TestCase):
89
server: VisionIpcServer
910
client: Optional[VisionIpcClient]
1011

pyproject.toml

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ dependencies = [
2020
"parameterized",
2121
"coverage",
2222
"numpy",
23-
"pytest",
24-
"pytest-retry",
2523
"cppcheck",
2624
"cpplint",
2725
"codespell",
@@ -38,20 +36,9 @@ lint.flake8-implicit-str-concat.allow-multiline=false
3836
line-length = 160
3937
target-version="py311"
4038

41-
[tool.ruff.lint.flake8-tidy-imports.banned-api]
42-
"pytest.main".msg = "pytest.main requires special handling that is easy to mess up!"
43-
"unittest".msg = "Use pytest"
44-
4539
[tool.ty.src]
4640
exclude = ["site_scons/"]
4741

4842
[tool.ty.rules]
4943
# Cython modules are compiled at build time, not available for static analysis
5044
unresolved-import = "ignore"
51-
52-
[tool.pytest.ini_options]
53-
addopts = "--durations=10"
54-
testpaths = [
55-
"msgq/tests",
56-
"msgq/visionipc/tests",
57-
]

0 commit comments

Comments
 (0)