Skip to content

Commit 9e88017

Browse files
committed
Fix multiple unclosed instances in tests
1 parent 2b502bc commit 9e88017

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

zeroconf/test.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,15 @@
3737
original_logging_level = logging.NOTSET
3838

3939

40+
@pytest.fixture(autouse=True)
41+
def verify_threads_ended():
42+
"""Verify that the threads are not running after the test."""
43+
threads_before = frozenset(threading.enumerate())
44+
yield
45+
threads = frozenset(threading.enumerate()) - threads_before
46+
assert not threads
47+
48+
4049
def setup_module():
4150
global original_logging_level
4251
original_logging_level = log.level
@@ -924,6 +933,7 @@ def send(out, addr=r._MDNS_ADDR, port=r._MDNS_PORT):
924933
zc.unregister_service(info)
925934
assert nbr_answers == 12 and nbr_additionals == 0 and nbr_authorities == 0
926935
nbr_answers = nbr_additionals = nbr_authorities = 0
936+
zc.close()
927937

928938
def test_name_conflicts(self):
929939
# instantiate a zeroconf instance
@@ -952,6 +962,7 @@ def test_name_conflicts(self):
952962
)
953963
with pytest.raises(r.NonUniqueNameException):
954964
zc.register_service(conflicting_info)
965+
zc.close()
955966

956967

957968
class TestServiceRegistry(unittest.TestCase):
@@ -1598,6 +1609,7 @@ def test_service_info_rejects_non_matching_updates(self):
15981609
),
15991610
)
16001611
assert new_address not in info.addresses
1612+
zc.close()
16011613

16021614
def test_get_info_partial(self):
16031615

@@ -2188,6 +2200,7 @@ def send(out, addr=r._MDNS_ADDR, port=r._MDNS_PORT):
21882200

21892201
# unregister
21902202
zc.unregister_service(info)
2203+
zc.close()
21912204

21922205

21932206
def test_dns_compression_rollback_for_corruption():

0 commit comments

Comments
 (0)