python - Access part of module from pytest -
i have issue accessing part of imported module pytest.
here branch code referenced below: https://github.com/asvc/snapshotr/tree/develop
in particular, when running test, works expected test_correct_installation() test_script_name_checking() fails attributeerror.
import main ss import os class testinit: def test_correct_installation(self): assert os.path.exists(ss.snapr_path) assert os.path.isfile(ss.snapr_path + "/main/markup.py") assert os.path.isfile(ss.snapr_path + "/main/scandir.py") def test_script_name_checking(self): assert ss.sspanel.check_script('blah') none # here fails what i'm trying "extract" isolated piece of code, run known data , compare result reference. seems extraction part doesn't work quite well, best practises such cases appreciated.
traceback: attributeerror: 'module' object has no attribute 'sspanel'
i have tried small hack in test_init.py:
class dummy(): pass nuke = dummy() nuke.gui = true but (obviously) doesn't work nuke.gui being redefined in __init__.py upon every launch.
this quite complex situation. when import main in test_init.py, import main/__init__.py , execute code. cause nuke being imported , also, if nuke.gui false, there not sspanel, can see.
the problem that, can't fake dummy nuke in test script. won't work. because before test running, real nuke imported.
my suggestion seperate sspanel python file. in __init__.py can do:
if nuke.gui: sspanel import sspanel and in test scripts, can import using:
from main.sspanel import sspanel
Comments
Post a Comment