Skip to content

Commit d700012

Browse files
committed
Skip ssh tests when system pytho too old.
1 parent 0501c71 commit d700012

File tree

6 files changed

+39
-1
lines changed

6 files changed

+39
-1
lines changed

tests/integration/cli/test_custom_module.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ def recho(text):
3232
import pytest
3333

3434
from tests.support.case import SSHCase
35+
from tests.support.helpers import system_python_version
3536

3637
pytestmark = [
3738
pytest.mark.skip_on_windows,
@@ -43,6 +44,10 @@ def recho(text):
4344
# has been deprecated since Python 3.7, so, the logic goes into trying to import
4445
# backports.ssl-match-hostname which is not installed on the system.
4546
),
47+
pytest.mark.skipif(
48+
system_python_version() < (3, 10),
49+
reason="System python too old for these tests",
50+
),
4651
]
4752

4853

tests/integration/ssh/test_state.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from saltfactories.utils.tempfiles import temp_file
1010

1111
from tests.support.case import SSHCase
12+
from tests.support.helpers import system_python_version
1213
from tests.support.runtests import RUNTIME_VARS
1314

1415
pytestmark = [
@@ -22,6 +23,10 @@
2223
# has been deprecated since Python 3.7, so, the logic goes into trying to import
2324
# backports.ssl-match-hostname which is not installed on the system.
2425
),
26+
pytest.mark.skipif(
27+
system_python_version() < (3, 10),
28+
reason="System python too old for these tests",
29+
),
2530
]
2631

2732
SSH_SLS = "ssh_state_tests"

tests/pytests/integration/netapi/test_ssh_client.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@
44

55
import salt.netapi
66
from salt.exceptions import EauthAuthenticationError, SaltInvocationError
7-
from tests.support.helpers import SaveRequestsPostHandler, Webserver
7+
from tests.support.helpers import (
8+
SaveRequestsPostHandler,
9+
Webserver,
10+
system_python_version,
11+
)
812
from tests.support.mock import patch
913

1014
pytestmark = [
@@ -18,6 +22,10 @@
1822
# has been deprecated since Python 3.7, so, the logic goes into trying to import
1923
# backports.ssl-match-hostname which is not installed on the system.
2024
),
25+
pytest.mark.skipif(
26+
system_python_version() < (3, 10),
27+
reason="System python too old for these tests",
28+
),
2129
pytest.mark.timeout_unless_on_windows(120),
2230
]
2331

tests/pytests/integration/ssh/conftest.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import pytest
22

3+
from tests.support.helpers import system_python_version
34
from tests.support.pytest.helpers import reap_stray_processes
45

56

@@ -16,6 +17,8 @@ def _auto_skip_on_system_python_too_recent(grains):
1617
# has been deprecated since Python 3.7, so, the logic goes into trying to import
1718
# backports.ssl-match-hostname which is not installed on the system.
1819
)
20+
if system_python_version() < (3, 10):
21+
pytest.skip("System python too old for these tests")
1922

2023

2124
@pytest.fixture(autouse=True)

tests/pytests/integration/ssh/state/test_retcode_highstate_verification_requisite_fail.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,14 @@
66
import pytest
77

88
from salt.defaults.exitcodes import EX_AGGREGATE
9+
from tests.support.helpers import system_python_version
910

1011
pytestmark = [
1112
pytest.mark.skip_on_windows(reason="salt-ssh not available on Windows"),
13+
pytest.mark.skipif(
14+
system_python_version() < (3, 10),
15+
reason="System python too old for these tests",
16+
),
1217
pytest.mark.slow_test,
1318
]
1419

tests/support/helpers.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1904,3 +1904,15 @@ def __enter__(self):
19041904

19051905
def __exit__(self, *_):
19061906
shutil.rmtree(str(self.priv_path.parent), ignore_errors=True)
1907+
1908+
1909+
@functools.cache
1910+
def system_python_version():
1911+
if salt.utils.platform.is_windows():
1912+
binary = "python3.exe"
1913+
else:
1914+
binary = "/usr/bin/python3"
1915+
proc = subprocess.run([binary, "--version"], capture_output=True, check=True)
1916+
return tuple(
1917+
int(_) for _ in proc.stdout.decode().split(" ", 1)[1].strip().split(".")
1918+
)

0 commit comments

Comments
 (0)