functional tests: Add pytest testinfra plugin

Adds ability to run local commands with functional tests.

By default, commands are run locally. It is possible to set remote
host connection parameters from pytest command line, for example:
`--hosts 'fbx@IP' --ssh-identity-file '.container/ssh/id_ed25519'`

For more options, see documentation
https://testinfra.readthedocs.io/en/latest/backends.html#ssh.

Includes a fixture `host_sudo` to run commands as sudo.

Relates to
https://salsa.debian.org/freedombox-team/freedombox/-/issues/2451#note_530752.

Signed-off-by: Veiko Aasa <veiko17@disroot.org>
Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
This commit is contained in:
Veiko Aasa authored and Sunil Mohan Adapa committed 2024-10-23 21:24:28 -07:00
1 parent f12e634bc9
commit b67ce15f89
2 files changed
+10 -2

No files matched your search

+8 -1
View File
@@ -223,7 +223,7 @@ def fixture_fix_session_browser_screenshots(request):
continue
value = fixture_def.cached_result[0]
should_take_screenshot = (hasattr(value, "__splinter_browser__")
should_take_screenshot = (hasattr(value, '__splinter_browser__')
and splinter_make_screenshot_on_failure
and getattr(request.node, 'splinter_failure',
True))
@@ -250,3 +250,10 @@ def fixture_fix_session_browser_screenshots(request):
}
plugin._take_screenshot(**kwargs)
@pytest.fixture(name='host_sudo')
def fixture_host_sudo(host):
"""Pytest fixture to run commands with sudo."""
with host.sudo():
yield host
+2 -1
View File
@@ -5,7 +5,8 @@ IFS=$'\n\t'
echo "Installing requirements"
sudo apt-get install -yq --no-install-recommends \
python3-pytest python3-pytest-django python3-pytest-instafail \
python3-pytest-xdist python3-pip python3-wheel firefox-esr git smbclient
python3-pytest-xdist python3-pip python3-wheel firefox-esr git smbclient \
python3-testinfra
# Use compatible versions of Splinter and Selenium
PIP_VERSION=$(dpkg-query -W -f '${Version}' python3-pip)