Skip to content

Commit

Permalink
tests/py: Add helpers for figuring out if tests run in CI or containers
Browse files Browse the repository at this point in the history
Which is useful for skipping test with the @pytest.mark.skipif
decorator.
  • Loading branch information
swick authored and GeorgesStavracas committed Dec 11, 2024
1 parent 26403d9 commit 6e09e84
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
12 changes: 12 additions & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from itertools import count
from typing import Any, Dict, Optional, NamedTuple, Callable

import os
import dbus
import dbus.proxies
import dbusmock
Expand All @@ -27,6 +28,17 @@
logger = logging.getLogger("tests")


def is_in_ci() -> bool:
return os.environ.get("XDP_TEST_IN_CI") is not None


def is_in_container() -> bool:
return is_in_ci() or (
"container" in os.environ
and (os.environ["container"] == "docker" or os.environ["container"] == "podman")
)


def wait(ms: int):
"""
Waits for the specified amount of milliseconds.
Expand Down
12 changes: 1 addition & 11 deletions tests/test_usb.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,17 +188,7 @@ def cb_device_events(session_handle, events):
)

@pytest.mark.parametrize("usb_queries", ["vnd:04a9", None])
@pytest.mark.skipif(
("GITHUB_ACTIONS" in os.environ and os.environ["GITHUB_ACTIONS"] == "true")
or (
"container" in os.environ
and (
os.environ["container"] == "docker"
or os.environ["container"] == "podman"
)
),
reason="Test fail in containers",
)
@pytest.mark.skipif(xdp.is_in_container(), reason="Test fail in containers")
def test_device_remove(self, portals, dbus_con, app_id, usb_queries, umockdev):
usb_intf = xdp.get_portal_iface(dbus_con, "Usb")

Expand Down

0 comments on commit 6e09e84

Please sign in to comment.