Closed ashok-s-nair closed 1 month ago
Hi,
thanks for the detailed setup description, that made it very easy to reproduce!
The issue lies with the import: With a statement like "from ..X import ..." --> the X is defined as the imported module.
So if you set utils_name = "test_games.src.utils"
, the test passes - but that's not quite what you want to test, I think.
To achieve what you're going for, I'd recommend specifying the import as absolute: import src.utils.gameutilities as GameUtilities
. In my test setup, this results in a green test.
Does that solve your problem?
Hello @zyskarch Thank you for your prompt and helpful response.
Changing the relative import to an absolute import (import src.utils.gameutilities as GameUtilities
) fixed the problem.
Could the point about discouraging relative imports be added (maybe as a footnote or similar) to the README? It might be helpful for other users. Thank you for your consideration.
I'll close this query as resolved.
Label Type:
question
Issue Type: Request for clarification
Environment Linux Mint 21.3 (kernel
5.15.0-117-generic
), running Python 3.10.12 usingpytestarch == 3.0.1
Background
My project path is
/home/developer/python/snakes-and-ladders-engine
and it has the folder structure:The
gameutilities.py
module contains only methods - no classes are defined in the file.game.py
importsgameutilities.py
asIn
test_architecture.py
, apytest
fixture returns an evaluable architecture.Question
I am trying to define the rule "
gameutilities
should be imported bygame
" using apytest
test.This fails with the result
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!
I have attached the trace of the error as a text file for reference. err_trace.txt