Reputation: 15
How can I import NestedValueError class & validate_item function from modules into test.py ?
Should I use conftest.py as a mediator between modules and tests file or something?
# /modules/errors.py
class EmptyValueError(Exception):
pass
#/modules/validate_item.py
def validate_item():
pass
#/tests/test.py
import pytest
def test_item_validate_exception_nested_value():
with pytest.raises(EmptyValueError):
validate_item({})
Upvotes: 0
Views: 53
Reputation: 37227
Simple:
from modules.errors import EmptyValueError
from modules.validate_item import validate_item
But be sure to run pytest in /
, with the following command:
python3 -m pytest test/
From pytest documentation (linked above):
This is almost equivalent to invoking the command line script
pytest [...]
directly, except that calling viapython
will also add the current directory tosys.path
.
Upvotes: 1