Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Please explain in README how to run tests #7

Closed
yurivict opened this issue Jul 1, 2022 · 3 comments
Closed

Please explain in README how to run tests #7

yurivict opened this issue Jul 1, 2022 · 3 comments

Comments

@yurivict
Copy link

yurivict commented Jul 1, 2022

PyTest fails even though Python module is in PYTHONPATH.

==================================================================================== test session starts =====================================================================================
platform freebsd13 -- Python 3.9.13, pytest-7.1.2, pluggy-1.0.0 -- /usr/local/bin/python3.9
cachedir: .pytest_cache
hypothesis profile 'default' -> database=DirectoryBasedExampleDatabase('/disk-samsung/freebsd-ports/textproc/py-jarowinkler/work-py39/jarowinkler-1.0.5/.hypothesis/examples')
rootdir: /disk-samsung/freebsd-ports/textproc/py-jarowinkler/work-py39/jarowinkler-1.0.5
plugins: forked-1.4.0, rerunfailures-10.1, hypothesis-6.47.3, xdist-2.5.0, cov-2.9.0
collected 0 items / 2 errors                                                                                                                                                                 

=========================================================================================== ERRORS ===========================================================================================
_________________________________________________________________________ ERROR collecting tests/test_JaroWinkler.py _________________________________________________________________________
ImportError while importing test module '/disk-samsung/freebsd-ports/textproc/py-jarowinkler/work-py39/jarowinkler-1.0.5/tests/test_JaroWinkler.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
/usr/local/lib/python3.9/importlib/__init__.py:127: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
tests/test_JaroWinkler.py:7: in <module>
    from jarowinkler import jarowinkler_similarity
jarowinkler/__init__.py:5: in <module>
    from ._initialize import *
E   ModuleNotFoundError: No module named 'jarowinkler._initialize'
_________________________________________________________________________ ERROR collecting tests/test_hypothesis.py __________________________________________________________________________
ImportError while importing test module '/disk-samsung/freebsd-ports/textproc/py-jarowinkler/work-py39/jarowinkler-1.0.5/tests/test_hypothesis.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
/usr/local/lib/python3.9/importlib/__init__.py:127: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
tests/test_hypothesis.py:5: in <module>
    from jarowinkler import jarowinkler_similarity
jarowinkler/__init__.py:5: in <module>
    from ._initialize import *
E   ModuleNotFoundError: No module named 'jarowinkler._initialize'
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Interrupted: 2 errors during collection !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
===================================================================================== 2 errors in 1.21s ======================================================================================
*** Error code 2
@maxbachmann
Copy link
Member

This issue occurs when a relative import is resolved to the local jarowinkler directory instead of the installed package. This local directory does not include the _initialize.so, since this is built as part of the installation. I just tried this locally and it appears:

python3 -m pytest

and

python3 -m pytest tests

picks up the wrong import path while

pytest

and

cd tests
python3 -m pytest

work fine. Not sure why this leads to a different import behavior though.

@maxbachmann
Copy link
Member

maxbachmann commented Jul 1, 2022

Ah it is described here: https://docs.pytest.org/en/7.1.x/explanation/pythonpath.html#pytest-vs-python-m-pytest
Appears you have to move the sources from /jarowinkler into /src/jarowinkler to prevent this. Not a big fan of this ugliness, but will change it in the next release to please the tools 🤷‍♂️
I will release a patch version with the change tomorrow

@yurivict
Copy link
Author

yurivict commented Jul 5, 2022

Tests now run.

Thanks!

@yurivict yurivict closed this as completed Jul 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants