Вот моя структура каталогов. (Я удалил word_count_test.py
, это стоило попробовать, содержимое было точно таким же, как test_word_count.py
).
Код для модульного тестирования в word_count.py
from validators import url
def isValidUrl(uri):
return url(uri)
test_word_count.py
содержит
import pytest
from src.word_count import isValidUrl
def isValidUrl_test():
assertTrue(isValidUrl("http://www.bbc.co.uk/news"))
assert 1 == 1
В зависимости от того, запускаю ли я pytest из терминала или из IDE, я получаю
__________________ ERROR collecting test/test_word_count.py ____________________________
ImportError while importing test module '/Users/path/to/the/project/word_counter_service/test/test_word_count.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
test/test_word_count.py:2: in <module>
from src.word_count import isValidUrl
E ModuleNotFoundError: No module named 'src'
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Interrupted: 1 error during collection !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
============================================================================================= 1 error in 0.10s =============================================================================================
или
word_counter_service) mc-n357353:word_counter_service leives01$ pytest
=========================================================== test session starts ===========================================================
platform darwin -- Python 3.8.0, pytest-5.3.2, py-1.8.1, pluggy-0.13.1
rootdir: /Users/path/to/the/project/word_counter_service
collected 0 items
========================================================== no tests ran in 0.10s ==========================================================