Closed Nauman702 closed 2 years ago
Or I have to do from findoutlie.detectors import iqr_detector
Or I have to do from findoutlie.detectors import iqr_detector
The comments in the file suggest to modify sys.path
, but the more resilient thing is either to use from findoutlie.detectors import iqr_detector
(will work right now) or from ..detectors import iqr_detector
(which will require turning your test directory into a directory module by adding an __init__.py
).
I would at least recommend looking at the solution and understanding why it works, but then you can go ahead and do what you're proposing.
The reason the comments suggest the more brittle approach is that this is intended to walk you through a progression that most new Python programmers go through, which is trying to figure out how to get their modules loaded and make progress on their code before constructing them into a proper package. Modifying sys.path
will get the job done, while configuring a package correctly can take time and frustration. We gave you a pre-configured package to prevent it from blocking you from doing the project, but that can make things appear misleadingly simple.
@effigies Thank you Chris for the explanation. I found out if I use from findoutlie.detectrors import iqr_detection
then i can only test it with pytest. It still doesn't find the module if I just run test_detectors.py.
Is it correct way of adding path to the python sys.path import sys
sys.path.insert(0, "/diagnostics-NME/findoutlie")
, its not working though.
Thank you
@effigies Thats fine. I found out. sys.path.append worked and both test runs work. Thank you again.
Right, we need to get findoutlie
onto your path. If your absolute path is /diagnostics-NME/findoutlie
, then sys.path.insert(0, "/diagnostics-NME")
would allow it to be found.
I would recommend instead using pip install -e .
in your repository directory, which will install your package in "editable mode".
@Nauman702 hey, before proceeding for the tests it was asked to install the "findoutlie" directory as mentioned here : https://apps.learn.nipraxis.org/learning/course/course-v1:Nipraxis+NI1+Fall2022/block-v1:Nipraxis+NI1+Fall2022+type@sequential+block@5ba09e862c8647ed8f4b56082f9baff7/block-v1:Nipraxis+NI1+Fall2022+type@vertical+block@1f168b5888ce4d5c86f38e99eb9eab63 I guess, you might have missed this. Actually I too made the same mistake.
@effigies Hi, it looks like there is another issue. When I run python -m pytest .\findoutlie\tests\test_detectors.py, it gives me an error, unable to find detectors.py module. I have to manually put detectors.py module in the test folder to make it work. Is there something wrong or I am not on the right track?
Thank you