0

The source in hypothesis_test.py, I have:

from utils import collapse_contiguous_ranges, check_number_in_range
@given(st.lists(st.integers()))
def test_collapse_contiguous_ranges(range: list[int]):
    collapsed = collapse_contiguous_ranges(range)
    for i in range:
        assert check_number_in_range(i, collapsed)
    assert collapse_contiguous_ranges(range) == [range[0], range[-1]]

Here is my command and my error:

 python -u "/Users/pitosalas/mydev/public-131-samples/memsim/memsim/tests/hypothesis_test.py"
Traceback (most recent call last):
  File "/Users/pitosalas/mydev/public-131-samples/memsim/memsim/tests/hypothesis_test.py", line 3, in <module>
    from utils import collapse_contiguous_ranges, check_number_in_range
ModuleNotFoundError: No module named 'utils'

And here is my directory structure. I've been stuck here before in other apps. I always mess around and sometimes it starts working. What can I try next?

enter image description here

4
  • check this question, how-do-i-import-other-python-files it should help Commented Nov 30, 2023 at 0:58
  • You probably want to run python -m memsim.tests.hypothesis_test from the upper memsim directory, and change the import to from memsim.utils import ... Then you will have a consistent sys.path that should work reliably. Commented Nov 30, 2023 at 1:03
  • 1
    utils.py is not in the same directory as hypothesis_test.py. Can you say why you expected the import to work? Commented Nov 30, 2023 at 2:50
  • 1
    Is this what you're looking for? Python import src modules when running tests. Especially see Joooeey's answer for advice about "src". Commented Feb 20, 2024 at 0:42

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.