Label Type: question
Issue Type: Request for clarification
Environment
Linux Mint 21.3 (kernel 5.15.0-117-generic
), running Python 3.10.12 using pytestarch == 3.0.1
Background
- My project path is
/home/developer/python/snakes-and-ladders-engine
and it has the folder structure:
├── src
│ ├── game
│ │ └── game.py
│ └── utils
│ └── gameutilities.py
└── tests
└── architecture
└── test_architecture.py
-
The
gameutilities.py
module contains only methods – no classes are defined in the file. -
game.py
importsgameutilities.py
as
from ..utils import gameutilities as GameUtilities
- In
test_architecture.py
, apytest
fixture returns an evaluable architecture.
@pytest.fixture
def game_architecture_instance(project_root: Path, src_root: Path) -> EvaluableArchitecture:
return get_evaluable_architecture(str(project_root), str(src_root))
Question
I am trying to define the rule “gameutilities
should be imported by game
” using a pytest
test.
def test_utilities_invocation_rule(game_architecture_instance: EvaluableArchitecture) -> None:
utils_name: str = "snakes-and-ladders-engine.src.utils.gameutilities"
game_name: str = "snakes-and-ladders-engine.src.game.game"
utilities_invocation_rule: Rule = (
Rule().modules_that()
.are_named(utils_name)
.should_only().be_imported_by_modules_that()
.are_named(game_name)
)
utilities_invocation_rule.assert_applies(game_architecture_instance)
This fails with the result
AssertionError: "snakes-and-ladders-engine.src.utils.gameutilities" is not imported by "snakes-and-ladders-engine.src.game.game".
Other functional tests under the test
tree work fine, and only the architecture test seems to be failing.
Is the rule misconfigured? What am I doing wrong here? Any support on how to fix this error is much appreciated – thank you!