Open Avitalrosner opened 2 weeks ago
Hi,
I get this error
$ pytest
===================================== test session starts ======================================
platform linux -- Python 3.12.3, pytest-8.2.0, pluggy-1.5.0
rootdir: /home/gabor/git/Weizmann-2024-04/Avital-Rosner-project
plugins: anyio-4.3.0
collected 0 items / 1 error
============================================ ERRORS ============================================
___________________________ ERROR collecting tests/test_analysis.py ____________________________
ImportError while importing test module '/home/gabor/git/Weizmann-2024-04/Avital-Rosner-project/tests/test_analysis.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
/usr/lib/python3.12/importlib/__init__.py:90: in import_module
return _bootstrap._gcd_import(name[level:], package, level)
tests/test_analysis.py:6: in <module>
from GTEx import get_marker_genes
E ModuleNotFoundError: No module named 'GTEx'
=================================== short test summary info ====================================
ERROR tests/test_analysis.py
!!!!!!!!!!!!!!!!!!!!!!!!!!!! Interrupted: 1 error during collection !!!!!!!!!!!!!!!!!!!!!!!!!!!!
======================================= 1 error in 0.72s =======================================
Hi, I think I understand the problem - when running pytest on the main directory it works:
PS C:\python\Fat_tissue_analysis> pytest
======================================= test session starts ========================================
platform win32 -- Python 3.10.2, pytest-8.2.0, pluggy-1.5.0
rootdir: C:\python\Fat_tissue_analysis
plugins: allure-pytest-2.13.5, anyio-4.4.0, Faker-25.2.0, json-report-1.5.0, metadata-3.1.1, order-1.
2.1, reportportal-5.1.5, rerunfailures-14.0, xdist-3.6.1
collected 4 items
tests\test_analysis.py .... [100%]
======================================== 4 passed in 12.44s ========================================
But when you run pytest within this "tests/test_analysis.py" it doesn't work. I created the GTEx.py from the original GTEx.ipynb, and changed the path in the test_analysis. So now it should recognize everything smoothly.
This is how I see it:
PS C:\python\Fat_tissue_analysis> cd C:\python\Fat_tissue_analysis\tests
PS C:\python\Fat_tissue_analysis\tests> pytest
======================================= test session starts ========================================
platform win32 -- Python 3.10.2, pytest-8.2.0, pluggy-1.5.0
rootdir: C:\python\Fat_tissue_analysis\tests
plugins: allure-pytest-2.13.5, anyio-4.4.0, Faker-25.2.0, json-report-1.5.0, metadata-3.1.1, order-1.
2.1, reportportal-5.1.5, rerunfailures-14.0, xdist-3.6.1
collected 4 items
test_analysis.py .... [100%]
======================================== 4 passed in 11.49s ========================================
Right, but this means that the tests are not testing the code in the jupyter notebook. After changing the code in the notebook you will still need to remember to export it. It would be better if the implementation was only in the .py file.
So convert your code into functions, move them to an external file (that can be called GTEx.py) and in the notebook import the function from that module. That way the test can test the real code.
It is also more common to run pytest
in the root of the project.
Besides I just noticed that something created a folder called C:/
in the test folder and also there is a folder called .ipynb_checkpoints/
which is not in gitignore
BTW Have you asked someone else in the course to review your project?
Good afternoon,
Here is a link to the repository with my final project: https://github.com/Avitalrosner/Fat_tissue_analysis/tree/main
The repository contains:
README.md file with background, technical info on the code, instructions regarding the dependencies, running the jupyter notebook and the tests.
The code in - "GTEx.ipynb", the input file - "GTEx_Analysis_2017-06-05_v8_RNASeQCv1.1.9_gene_median_tpm.gct"
Requirements.txt file.
Two output files - "vis.csv" and "sub.csv".
Tests directory with a test_analysis.py file.
Additional files - two jpg files for the readme, a gitignore file for pycache.
Ps. I have submitted 9 assignments throughout the course, and the timestamps was in a separate issue that you confirmed (https://github.com/szabgab/wis-python-course-2024-04/issues/92).
Thank you for this informative course, I've learned a lot! Shabbat shalom :) Avital