hoping someone can help me out setting up pytest.
This is my attempt at writing a test for my super-basic class:
test_message.py:
from crmpicco.subtasks.legacy import Legacy
def test_is_complete(self):
legacy = Legacy()
assert legacy.is_complete(self) == True
legacy.py looks like this:
from crmpicco.subtasks.subtask import Subtask
class Legacy(Subtask):
def execute(self):
print("legacy")
def is_complete(self):
return True
When I run the test from the directory the class lives in it can't seem to reference or find the "crmpicco" module for some reason...
pytest test_message.py
ERROR collecting test_message.py _______________________________________________________________
ImportError while importing test module '/private/var/www/crmpicco/crmpicco/subtasks/test_message.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
/usr/local/Cellar/python@3.9/3.9.6/Frameworks/Python.framework/Versions/3.9/lib/python3.9/importlib/__init__.py:127: in import_module
return _bootstrap._gcd_import(name[level:], package, level)
test_message.py:1: in <module>
from crmpicco.subtasks.legacy import Legacy
E ModuleNotFoundError: No module named 'crmpicco'
What am I doing wrong? Any help is appreciated, thanks :-)
You have installed PyTest and made sure it worked with the code snippet available in the docs before trying to make it work with your own tailored code, haven't you?
Thanks for the reply. Yes, I can run a simple test without any issues. I can also run the test if I move it into that directory, so clear there's an issue with the "crmpicco" module or how I am referencing it when I have the test in a separate /tests directory. Can you spot the issue from my code above?
Обсуждают сегодня