Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix failing tests on Fedora 40 #381

Merged
merged 5 commits into from
Sep 17, 2024
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
2 changes: 1 addition & 1 deletion src/wakepy/core/method.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class Method(ABC):
registered anywhere)"""

supported_platforms: Tuple[PlatformType, ...] = (PlatformType.ANY,)
"""Lists the platforms the Method supports. If the current platform is not
r"""Lists the platforms the Method supports. If the current platform is not
part of any of the platform types listed in ``method.supported_platforms``,
the ``method`` is not* going to be used (when used as part of a
:class:`Mode`), and the Method activation result will show a fail in the
Expand Down
1 change: 1 addition & 0 deletions tests/integration/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ def gc_collect_after_dbus_integration_tests():
# this as garbage colletion is triggered also automatically. The garbage
# collection must be triggered here manually as the warnings are
# ResourceWarning is only filtered away in the dbus integration tests.
# See also: comments for pytestmark in tests/integration/test_dbus_adapters.py # noqa: W505, E501
gc.collect()

logger.debug("called gc.collect")
Expand Down
32 changes: 27 additions & 5 deletions tests/integration/test_dbus_adapters.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,41 @@
from wakepy.core import DBusAddress, DBusMethod, DBusMethodCall
from wakepy.dbus_adapters.jeepney import DBusNotFoundError

# For some unknown reason, when using jeepney, one will get a warning like
# this:
# For some unknown reason the D-Bus integration tests emit warnings like
#
# ResourceWarning: unclosed <socket.socket fd=14, family=AddressFamily.AF_UNIX, type=SocketKind.SOCK_STREAM, proto=0, raddr=b'\x00/tmp/dbus-cTfPKAeBWk'> # noqa: E501, W505
# This is just ignored. It only triggers at *random* line, on random test when
# python does garbage collection.
# or
# ResourceWarning: unclosed <socket.socket fd=14, family=1, type=1, proto=0, raddr=/tmp/dbus-WkEJOPjiAu> # noqa: E501, W505
#
# on garbage collection (either automatic; on any line or manual; during
# gc_collect_after_dbus_integration_tests). These warnings are expected and
# harmless. They occur either because a bug or some feature present in the DBus
# Service or the interactions with the DBus service in the integration tests.
# These do not happen during normal usage of wakepy and do not affect wakepy
# users and are therefore simply ignored.
#
# Ref1: https://docs.pytest.org/en/7.1.x/reference/reference.html#pytest-mark-filterwarnings
# Ref2: https://docs.pytest.org/en/7.1.x/reference/reference.html#globalvar-pytestmark
# Ref3: https://github.com/fohrloop/wakepy/issues/380
ignore_resource_warning_regex = r"unclosed <socket.*raddr=[^=]*/tmp/dbus-.*"
pytestmark = pytest.mark.filterwarnings(
r"ignore:unclosed.*raddr=b'\\x00/tmp/dbus-.*:ResourceWarning"
f"ignore:{ignore_resource_warning_regex}:ResourceWarning"
)


def test_pytestmark_regex_okay():
# Tests that the regex used in the pytestmark ignores the warning strings
# that have been occurred.
examples = [
# On Ubuntu:
r"""unclosed <socket.socket fd=14, family=AddressFamily.AF_UNIX, type=SocketKind.SOCK_STREAM, proto=0, raddr=b'\x00/tmp/dbus-cTfPKAeBWk'>""", # noqa: E501
# On Fedora 40
r"""unclosed <socket.socket fd=14, family=1, type=1, proto=0, raddr=/tmp/dbus-WkEJOPjiAu>""", # noqa: E501
]
for warning_example in examples:
assert re.match(ignore_resource_warning_regex, warning_example)


@pytest.mark.usefixtures("dbus_calculator_service")
class TestJeepneyCalculatorService:

Expand Down