Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,11 @@
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
USA
"""

from zeroconf.core import Zeroconf
from zeroconf.dns import DNSIncoming


def _inject_response(zc: Zeroconf, msg: DNSIncoming) -> None:
"""Inject a DNSIncoming response."""
zc.handle_response(msg)
18 changes: 18 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-


""" conftest for zeroconf tests. """

import threading

import pytest


@pytest.fixture(autouse=True)
def verify_threads_ended():
"""Verify that the threads are not running after the test."""
threads_before = frozenset(threading.enumerate())
yield
threads = frozenset(threading.enumerate()) - threads_before
assert not threads
18 changes: 18 additions & 0 deletions tests/test_aio.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import asyncio
import socket
import threading
import unittest.mock

import pytest
Expand All @@ -23,6 +24,23 @@
from zeroconf.aio import AsyncServiceInfo, AsyncServiceListener, AsyncZeroconf


@pytest.fixture(autouse=True)
def verify_threads_ended():
"""Verify that the threads are not running after the test."""
threads_before = frozenset(threading.enumerate())
yield
threads_after = frozenset(threading.enumerate())
non_executor_threads = frozenset(
[
thread
for thread in threads_after
if "asyncio" not in thread.name and "ThreadPoolExecutor" not in thread.name
]
)
threads = non_executor_threads - threads_before
assert not threads


@pytest.mark.asyncio
async def test_async_basic_usage() -> None:
"""Test we can create and close the instance."""
Expand Down
19 changes: 18 additions & 1 deletion tests/test_asyncio.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,29 @@

"""Unit tests for asyncio.py."""


import pytest
import threading

from zeroconf.asyncio import AsyncZeroconf


@pytest.fixture(autouse=True)
def verify_threads_ended():
"""Verify that the threads are not running after the test."""
threads_before = frozenset(threading.enumerate())
yield
threads_after = frozenset(threading.enumerate())
non_executor_threads = frozenset(
[
thread
for thread in threads_after
if "asyncio" not in thread.name and "ThreadPoolExecutor" not in thread.name
]
)
threads = non_executor_threads - threads_before
assert not threads


@pytest.mark.asyncio
async def test_async_basic_usage() -> None:
"""Test we can create and close the instance."""
Expand Down
9 changes: 0 additions & 9 deletions tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,6 @@
original_logging_level = logging.NOTSET


@pytest.fixture(autouse=True)
def verify_threads_ended():
"""Verify that the threads are not running after the test."""
threads_before = frozenset(threading.enumerate())
yield
threads = frozenset(threading.enumerate()) - threads_before
assert not threads


def setup_module():
global original_logging_level
original_logging_level = log.level
Expand Down
Loading