dimanche 5 janvier 2020

Pytest not running as expected, module not found or collected 0 items

Here is my directory structure. (I deleted word_count_test.py it was worth a try, the content was exactly the same as test_word_count.py).

directory structure

The code for unit testing in word_count.py

from validators import url

def isValidUrl(uri):
    return url(uri)

test_word_count.py contains

import pytest
from src.word_count import isValidUrl

def isValidUrl_test():
    assertTrue(isValidUrl("http://www.bbc.co.uk/news"))

assert 1 == 1

Depending on whether I run pytest from the terminal or from within the IDE I get

__________________ 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 =============================================================================================

or

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 ==========================================================

Aucun commentaire:

Enregistrer un commentaire