From aace46a2d3c72db2bcf4e6ead859946d1d8243c6 Mon Sep 17 00:00:00 2001 From: Fernando Macedo Date: Sun, 26 Jan 2025 13:21:29 -0300 Subject: [PATCH] tests: Ignore tests that requires dot if the executable is not present --- README.md | 2 ++ conftest.py | 12 ++++++++++++ docs/diagram.md | 2 ++ docs/transitions.md | 3 +++ tests/test_contrib_diagram.py | 2 ++ 5 files changed, 21 insertions(+) diff --git a/README.md b/README.md index eb93ce9f..7e9274fa 100644 --- a/README.md +++ b/README.md @@ -99,6 +99,8 @@ You can now create an instance: This state machine can be represented graphically as follows: ```py +>>> # This example will only run on automated tests if dot is present +>>> getfixture("requires_dot_installed") >>> img_path = "docs/images/readme_trafficlightmachine.png" >>> sm._graph().write_png(img_path) diff --git a/conftest.py b/conftest.py index fcdcaf2c..4c2c0c63 100644 --- a/conftest.py +++ b/conftest.py @@ -1,3 +1,4 @@ +import shutil import sys import pytest @@ -31,3 +32,14 @@ def pytest_ignore_collect(collection_path, path, config): if "django_project" in str(path): return True + + +@pytest.fixture(scope="session") +def has_dot_installed(): + return bool(shutil.which("dot")) + + +@pytest.fixture() +def requires_dot_installed(request, has_dot_installed): + if not has_dot_installed: + pytest.skip(f"Test {request.node.nodeid} requires 'dot' that is not installed.") diff --git a/docs/diagram.md b/docs/diagram.md index 139970d4..8dae0aee 100644 --- a/docs/diagram.md +++ b/docs/diagram.md @@ -74,6 +74,8 @@ If you find the resolution of the image lacking, you can The current {ref}`state` is also highlighted: ``` py +>>> # This example will only run on automated tests if dot is present +>>> getfixture("requires_dot_installed") >>> from statemachine.contrib.diagram import DotGraphMachine diff --git a/docs/transitions.md b/docs/transitions.md index 1752224c..314fcc9f 100644 --- a/docs/transitions.md +++ b/docs/transitions.md @@ -131,6 +131,9 @@ Example: Usage: ```py +>>> # This example will only run on automated tests if dot is present +>>> getfixture("requires_dot_installed") + >>> sm = TestStateMachine() >>> sm._graph().write_png("docs/images/test_state_machine_internal.png") diff --git a/tests/test_contrib_diagram.py b/tests/test_contrib_diagram.py index b54a43d3..3b2516b3 100644 --- a/tests/test_contrib_diagram.py +++ b/tests/test_contrib_diagram.py @@ -7,6 +7,8 @@ from statemachine.contrib.diagram import main from statemachine.contrib.diagram import quickchart_write_svg +pytestmark = pytest.mark.usefixtures("requires_dot_installed") + @pytest.fixture( params=[