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 28164b6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ 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"):
if not os.environ.get("GITHUB_CI"):
has_github_ci_mark = any(mark for mark in item.iter_markers(name="github_ci"))
if has_github_ci_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_ci
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_ci
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_ci
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_ci
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_ci
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_ci
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_ci
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_ci
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_ci
async def test_uid_gid():
"""
Test setting uid and gid
Expand Down

0 comments on commit 28164b6

Please sign in to comment.