Skip to content

Commit dfd89ab

Browse files
authored
fix(tests): adding WSL2 support (#600)
Developers using WSL2 (Windows Subsystem for Linux) face the problem that there is currently no systemd support. For the test `test_iptables` a service is started and it fails on WSL2 hosts. This commit introduces a pytest marker to skip the test if the host is executing on WSL2.
1 parent 3d266ec commit dfd89ab

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

test/conftest.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,3 +264,7 @@ def build_image(build_failed, dockerfile, image, image_path):
264264
"markers",
265265
"destructive: mark test as destructive"
266266
)
267+
config.addinivalue_line(
268+
"markers",
269+
"skip_wsl: skip test on WSL, no systemd support"
270+
)

test/test_modules.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@
1212

1313
import crypt
1414
import datetime
15+
import os
16+
import pytest
1517
import re
1618
import time
1719

18-
import pytest
19-
2020
from ipaddress import ip_address
2121
from ipaddress import IPv4Address
2222
from ipaddress import IPv6Address
@@ -516,6 +516,8 @@ def test_environment_home(host):
516516
assert host.environment().get('HOME') == '/root'
517517

518518

519+
@pytest.mark.skipif('WSL_DISTRO_NAME' in os.environ,
520+
reason="Skip on WSL (Windows Subsystem for Linux)")
519521
def test_iptables(host):
520522
cmd = host.run("systemctl start netfilter-persistent")
521523
assert cmd.exit_status == 0, f"{cmd.stdout}\n{cmd.stderr}"

tox.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ deps=
1212
commands=
1313
{envpython} -m pytest {posargs:-v -n 4 --cov testinfra --cov-report xml --cov-report term test}
1414
usedevelop=True
15-
passenv=HOME TRAVIS DOCKER_CERT_PATH DOCKER_HOST DOCKER_TLS_VERIFY
15+
passenv=HOME TRAVIS DOCKER_CERT_PATH DOCKER_HOST DOCKER_TLS_VERIFY WSL_DISTRO_NAME
1616

1717
[testenv:lint]
1818
description = Performs linting tasks

0 commit comments

Comments
 (0)