Skip to content

Commit

Permalink
tests: Ignore tests that requires dot if the executable is not present
Browse files Browse the repository at this point in the history
  • Loading branch information
fgmacedo committed Jan 26, 2025
1 parent 9954890 commit aace46a
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
12 changes: 12 additions & 0 deletions conftest.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import shutil
import sys

import pytest
Expand Down Expand Up @@ -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.")
2 changes: 2 additions & 0 deletions docs/diagram.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 3 additions & 0 deletions docs/transitions.md
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
2 changes: 2 additions & 0 deletions tests/test_contrib_diagram.py
Original file line number Diff line number Diff line change
Expand Up @@ -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=[
Expand Down

0 comments on commit aace46a

Please sign in to comment.