Skip to content

Commit

Permalink
Add pytest mark to skip tests unless in github's CI system
Browse files Browse the repository at this point in the history
  • Loading branch information
consideRatio committed May 25, 2023
1 parent 5dd2a69 commit 29bb1aa
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
10 changes: 6 additions & 4 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def pytest_configure(config):
A pytest recognized function to adjust configuration before running tests.
"""
config.addinivalue_line(
"markers", "github_ci: only to be run in a github ci environment"
"markers", "github_actions: only to be run in a github actions ci environment"
)

# These markers are registered to avoid warnings triggered by importing from
Expand All @@ -37,9 +37,11 @@ def pytest_runtest_setup(item):
Several of these tests work against the host system directly, so to protect
users from issues we make these not run.
"""
if not os.environ("GITHUB_CI"):
has_github_ci_mark = any(mark for mark in item.iter_markers(name="github_ci"))
if has_github_ci_mark:
if not os.environ.get("GITHUB_ACTIONS"):
has_github_actions_mark = any(
mark for mark in item.iter_markers(name="github_actions")
)
if has_github_actions_mark:
pytest.skip("Skipping test marked safe only for GitHub's CI environment.")


Expand Down
11 changes: 11 additions & 0 deletions tests/test_systemd.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import tempfile
import time

import pytest

from systemdspawner import systemd


Expand All @@ -22,6 +24,7 @@ def test_get_systemd_version():
), "Either systemd wasn't running, or we failed to parse the version into an integer!"


@pytest.mark.github_actions
async def test_simple_start():
unit_name = "systemdspawner-unittest-" + str(time.time())
await systemd.start_transient_service(
Expand All @@ -35,6 +38,7 @@ async def test_simple_start():
assert not await systemd.service_running(unit_name)


@pytest.mark.github_actions
async def test_service_failed_reset():
"""
Test service_failed and reset_service
Expand All @@ -57,6 +61,7 @@ async def test_service_failed_reset():
assert not await systemd.service_failed(unit_name)


@pytest.mark.github_actions
async def test_service_running_fail():
"""
Test service_running failing when there's no service.
Expand All @@ -66,6 +71,7 @@ async def test_service_running_fail():
assert not await systemd.service_running(unit_name)


@pytest.mark.github_actions
async def test_env_setting():
unit_name = "systemdspawner-unittest-" + str(time.time())
with tempfile.TemporaryDirectory() as d:
Expand Down Expand Up @@ -107,6 +113,7 @@ async def test_env_setting():
assert not os.path.exists(env_file)


@pytest.mark.github_actions
async def test_workdir():
unit_name = "systemdspawner-unittest-" + str(time.time())
_, env_filename = tempfile.mkstemp()
Expand All @@ -126,6 +133,7 @@ async def test_workdir():
assert text == d


@pytest.mark.github_actions
async def test_slice():
unit_name = "systemdspawner-unittest-" + str(time.time())
_, env_filename = tempfile.mkstemp()
Expand All @@ -151,6 +159,7 @@ async def test_slice():
assert b"user.slice" in stdout


@pytest.mark.github_actions
async def test_properties_string():
"""
Test that setting string properties works
Expand Down Expand Up @@ -180,6 +189,7 @@ async def test_properties_string():
assert text == "/bind-test"


@pytest.mark.github_actions
async def test_properties_list():
"""
Test setting multiple values for a property
Expand Down Expand Up @@ -216,6 +226,7 @@ async def test_properties_list():
assert text == d


@pytest.mark.github_actions
async def test_uid_gid():
"""
Test setting uid and gid
Expand Down
2 changes: 1 addition & 1 deletion tests/test_systemdspawner.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def _get_systemdspawner_user_unit(username):
return user_unit


@pytest.mark.github_ci
@pytest.mark.github_actions
async def test_start_stop(hub_app, systemdspawner_config):
"""
This tests starts the default user server, access its /api/status endpoint,
Expand Down

0 comments on commit 29bb1aa

Please sign in to comment.