forked from hardbyte/python-can
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconftest.py
More file actions
24 lines (17 loc) · 684 Bytes
/
conftest.py
File metadata and controls
24 lines (17 loc) · 684 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import pytest
from can.interfaces import virtual
@pytest.fixture(autouse=True)
def check_unclosed_virtual_channel():
"""
Pytest fixture for detecting leaked virtual CAN channels.
- The fixture yields control to the test.
- After the test completes, it acquires `virtual.channels_lock` and asserts
that `virtual.channels` is empty.
- If a test leaves behind any unclosed virtual CAN channels, the assertion
will fail, surfacing resource leaks early.
This helps maintain test isolation and prevents subtle bugs caused by
leftover state between tests.
"""
yield
with virtual.channels_lock:
assert len(virtual.channels) == 0