sambit-giri / tools21cm

MIT License
22 stars 18 forks source link

Tests do not run with the command in README #7

Closed ziotom78 closed 4 years ago

ziotom78 commented 4 years ago

Running pytest -v as stated in the README causes the following errors:

$ pytest -v
===================================================================================== test session starts ======================================================================================
platform linux -- Python 3.7.6, pytest-5.4.3, py-1.9.0, pluggy-0.13.1 -- /home/tomasi/miniconda3/bin/python
cachedir: .pytest_cache
rootdir: /home/tomasi/Documents/work/articles/referee/JOSS/tools21cm/tools21cm
collected 0 items / 7 errors                                                                                                                                                                   

============================================================================================ ERRORS ============================================================================================
_______________________________________________________________________ ERROR collecting tests/test_BubbleStatistics.py ________________________________________________________________________
ImportError while importing test module '/home/tomasi/Documents/work/articles/referee/JOSS/tools21cm/tools21cm/tests/test_BubbleStatistics.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
tests/test_BubbleStatistics.py:2: in <module>
    from skimage.morphology import ball
E   ModuleNotFoundError: No module named 'skimage'
___________________________________________________________________________ ERROR collecting tests/test_CosmoCalc.py ___________________________________________________________________________
ImportError while importing test module '/home/tomasi/Documents/work/articles/referee/JOSS/tools21cm/tools21cm/tests/test_CosmoCalc.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
tests/test_CosmoCalc.py:2: in <module>
    import tools21cm as t2c
E   ModuleNotFoundError: No module named 'tools21cm'
________________________________________________________________________ ERROR collecting tests/test_IdentifyRegions.py ________________________________________________________________________
ImportError while importing test module '/home/tomasi/Documents/work/articles/referee/JOSS/tools21cm/tools21cm/tests/test_IdentifyRegions.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
tests/test_IdentifyRegions.py:2: in <module>
    from skimage.morphology import ball
E   ModuleNotFoundError: No module named 'skimage'
________________________________________________________________________ ERROR collecting tests/test_PointStatistics.py ________________________________________________________________________
ImportError while importing test module '/home/tomasi/Documents/work/articles/referee/JOSS/tools21cm/tools21cm/tests/test_PointStatistics.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
tests/test_PointStatistics.py:2: in <module>
    import tools21cm as t2c
E   ModuleNotFoundError: No module named 'tools21cm'
_________________________________________________________________________ ERROR collecting tests/test_PowerSpectrum.py _________________________________________________________________________
ImportError while importing test module '/home/tomasi/Documents/work/articles/referee/JOSS/tools21cm/tools21cm/tests/test_PowerSpectrum.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
tests/test_PowerSpectrum.py:2: in <module>
    import tools21cm as t2c
E   ModuleNotFoundError: No module named 'tools21cm'
___________________________________________________________________________ ERROR collecting tests/test_Smoothing.py ___________________________________________________________________________
ImportError while importing test module '/home/tomasi/Documents/work/articles/referee/JOSS/tools21cm/tools21cm/tests/test_Smoothing.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
tests/test_Smoothing.py:2: in <module>
    import tools21cm as t2c
E   ModuleNotFoundError: No module named 'tools21cm'
__________________________________________________________________________ ERROR collecting tests/test_Temperature.py __________________________________________________________________________
ImportError while importing test module '/home/tomasi/Documents/work/articles/referee/JOSS/tools21cm/tools21cm/tests/test_Temperature.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
tests/test_Temperature.py:2: in <module>
    from skimage.morphology import ball
E   ModuleNotFoundError: No module named 'skimage'
=================================================================================== short test summary info ====================================================================================
ERROR tests/test_BubbleStatistics.py
ERROR tests/test_CosmoCalc.py
ERROR tests/test_IdentifyRegions.py
ERROR tests/test_PointStatistics.py
ERROR tests/test_PowerSpectrum.py
ERROR tests/test_Smoothing.py
ERROR tests/test_Temperature.py
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Interrupted: 7 errors during collection !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
====================================================================================== 7 errors in 0.17s =======================================================================================

This can be fixed using the trick explained in a StackOverflow answer, i.e., using the command python -m pytest tests/:

$ python -m pytest tests/
===================================================================================== test session starts ======================================================================================
platform linux -- Python 3.7.6, pytest-5.4.3, py-1.9.0, pluggy-0.13.1
rootdir: /home/tomasi/Documents/work/articles/referee/JOSS/tools21cm/tools21cm
collected 25 items                                                                                                                                                                             

tests/test_BubbleStatistics.py ...                                                                                                                                                       [ 12%]
tests/test_CosmoCalc.py .                                                                                                                                                                [ 16%]
tests/test_IdentifyRegions.py ...                                                                                                                                                        [ 28%]
tests/test_PointStatistics.py .....                                                                                                                                                      [ 48%]
tests/test_PowerSpectrum.py .....                                                                                                                                                        [ 68%]
tests/test_Smoothing.py ....                                                                                                                                                             [ 84%]
tests/test_Temperature.py ....                                                                                                                                                           [100%]

======================================================================================= warnings summary =======================================================================================
tests/test_IdentifyRegions.py::test_bubbles_from_slic
  /home/tomasi/Documents/work/articles/referee/JOSS/tools21cm/venv/lib/python3.7/site-packages/skimage/util/dtype.py:226: DeprecationWarning: Converting `np.inexact` or `np.floating` to a dtype is deprecated. The current result is `float64` which is not strictly correct.
    dtypeobj_out = np.dtype(dtype)

tests/test_IdentifyRegions.py::test_bubbles_from_slic
  /home/tomasi/Documents/work/articles/referee/JOSS/tools21cm/venv/lib/python3.7/site-packages/tools21cm/superpixels.py:16: FutureWarning: skimage.measure.label's indexing starts from 0. In future version it will start from 1. To disable this warning, explicitely set the `start_label` parameter to 1.
    labels = slic(cube, n_segments=n_segments, compactness=compactness, max_iter=max_iter, sigma=sigma, max_size_factor=max_size_factor, slic_zero=True, multichannel=multichannel)

tests/test_IdentifyRegions.py::test_bubbles_from_slic
  /home/tomasi/Documents/work/articles/referee/JOSS/tools21cm/venv/lib/python3.7/site-packages/skimage/segmentation/slic_superpixels.py:262: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated since Python 3.3,and in 3.9 it will stop working
    if not isinstance(sigma, coll.Iterable):

tests/test_IdentifyRegions.py::test_bubbles_from_kmeans
tests/test_IdentifyRegions.py::test_bubbles_from_kmeans
  /home/tomasi/Documents/work/articles/referee/JOSS/tools21cm/venv/lib/python3.7/site-packages/sklearn/cluster/_kmeans.py:974: FutureWarning: 'n_jobs' was deprecated in version 0.23 and will be removed in 0.25.
    " removed in 0.25.", FutureWarning)

-- Docs: https://docs.pytest.org/en/latest/warnings.html
================================================================================ 25 passed, 5 warnings in 3.15s ================================================================================

Perhaps it would be good to update the README.

(This issue was triggered while reviewing the JOSS paper.)

sambit-giri commented 4 years ago

@ziotom78 Thanks for pointing this out.

Initially I was unable to reproduce this error. With a quick search, I found that this could be caused when pytest is installed outside of a virtual environment where the package is installed (https://medium.com/@dirk.avery/pytest-modulenotfounderror-no-module-named-requests-a770e6926ac5). I did it and got the error.

The fix you suggested is working in that case. I will add a comment about this in the README.

ziotom78 commented 4 years ago

With a quick search, I found that this could be caused when pytest is installed outside of a virtual environment where the package is installed (https://medium.com/@dirk.avery/pytest-modulenotfounderror-no-module-named-requests-a770e6926ac5). I did it and got the error.

Yes, this was indeed the case, but then I installed pytest under my virtualenv, downloaded and installed tools21cm again and the error kept popping out. I believe it's safer for the general user if you provide the python -m ptyest command.

sambit-giri commented 4 years ago

Okay, I will do that.

While testing from the package directory, the command should be python -m pytest tests/ and inside the tests directory, it should python -m pytest. Is this correct?

ziotom78 commented 4 years ago

While testing from the package directory, the command should be python -m pytest tests/ and inside the tests directory, it should python -m pytest. Is this correct?

Right, I can confirm it works in both ways.

sambit-giri commented 4 years ago

The README and the instructions in the readthedocs documentation have been updated.