From 1763eb3426d5b4f4f0d8e4bef950a843292a1690 Mon Sep 17 00:00:00 2001 From: JP-Ellis Date: Wed, 15 Nov 2023 16:43:32 +1100 Subject: [PATCH] chore(tests): automatic submodule init In order to reduce the burden for new contributors, I have added a pytest fixture which checks that the submodule has been created. If it is not, it will try and run `git submodule init`. Signed-off-by: JP-Ellis --- tests/v3/compatibility-suite/__init__.py | 3 +++ tests/v3/compatibility-suite/conftest.py | 30 ++++++++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 tests/v3/compatibility-suite/__init__.py create mode 100644 tests/v3/compatibility-suite/conftest.py diff --git a/tests/v3/compatibility-suite/__init__.py b/tests/v3/compatibility-suite/__init__.py new file mode 100644 index 0000000000..16228019ee --- /dev/null +++ b/tests/v3/compatibility-suite/__init__.py @@ -0,0 +1,3 @@ +""" +Compatibility suite tests. +""" diff --git a/tests/v3/compatibility-suite/conftest.py b/tests/v3/compatibility-suite/conftest.py new file mode 100644 index 0000000000..46d3d33cb5 --- /dev/null +++ b/tests/v3/compatibility-suite/conftest.py @@ -0,0 +1,30 @@ +""" +Pytest configuration. + +As the compatibility suite makes use of a submodule, we need to make sure the +submodule has been initialized before running the tests. +""" + +import shutil +import subprocess +from pathlib import Path + +import pytest + + +@pytest.fixture(scope="session", autouse=True) +def _submodule_init() -> None: + """Initialize the submodule.""" + # Locate the git execute + submodule_dir = Path(__file__).parent / "definition" + if submodule_dir.is_dir(): + return + + git_exec = shutil.which("git") + if git_exec is None: + msg = ( + "Submodule not initialized and git executable not found." + " Please initialize the submodule with `git submodule init`." + ) + raise RuntimeError(msg) + subprocess.check_call([git_exec, "submodule", "init"]) # noqa: S603