1

I am trying to package a software written in python for the first time and so I am now running tests through tox. The template was setup through cookiecutter. Then I added my code to sample and created a tests/ folder with a script that should test one method in the class contained under project_name.py

Unfortunately my test in tox always fails:

my package looks something like this

```
project 
│
└───sample
│       project_name.py
│       save_.py
|       data.pkl
|       __init__.py
│   
└───tests
        settings.txt
        test_project.py
```

The error that I am getting is the following

________________________________________ ERROR collecting tests/test_project.py _________________________________________
ImportError while importing test module'/home/user/Documents/project/tests/test_project.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
tests/test_project.py:6: in <module>
import sample.project as pr
sample/project_name.py:12: in <module>
    from save_ import Save
E   ModuleNotFoundError: No module named 'save_'

I have already tried to add a new PYTHONPATH that points to the folder in which I have the different scripts for my software, but that didn't work.

I have also tried to change the names because I thought that perhaps the underscore at the end of the module name wasn't a valid python name.

I have looked for other solutions on stackoverflow but I couldn't find anything that solved my problem.

Thanks in advance for any help you may be able to provide!

6F4E37
  • 55
  • 7
  • Add an empty `conftest.py` to the project dir: `touch project/conftest.py`. – hoefling May 12 '18 at 09:58
  • 1
    Possible duplicate of [pytest cannot find module](https://stackoverflow.com/questions/49028611/pytest-cannot-find-module) – hoefling May 12 '18 at 09:59
  • Thanks! I think this solved the problem. I am running over other issues now so I can't be 100%. I will come back later to close it because it indeed seems to be a duplicate now. – 6F4E37 May 12 '18 at 11:01
  • Hi the problem turned out to be not related to conftest.py but how I had set up my directory and how I was importing modules. It seems to be all fixed now. What I did was to change the import to be like an import from a subpackage and now its working! Thanks for your answer, I am going to also keep the conftest.py in the directory. – 6F4E37 May 17 '18 at 17:00

0 Answers0