0

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({})    

1 Answers1

1

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 via python will also add the current directory to sys.path.

iBug
  • 35,554
  • 7
  • 89
  • 134