Hello, I have a problem! When I want to run the test on the source code (ch2), I have an Import Error, yet I have the module in my virtualenv/Lib/sitepackages and I see it when I do a pip freeze. I on windows 10. Someone has an idea of what I doing wrong
I’ll try to reproduce the problem.
I tried to install the package globally and it works this way, but if it is just installed in my virtaulenv it doesn’t. If you have an explanation I’m interested, otherwise it doesn’t matter, it works now!
================================================ ERRORS ================================================= ___________________________________________ ERROR collecting ___________________________________________ ../../.local/lib/python3.5/site-packages/_pytest/config.py:330: in _getconftestmodules return self._path2confmods[path] E KeyError: local('/home/nicolas/Projects/code/ch3/a/tasks_proj/tests') During handling of the above exception, another exception occurred: ../../.local/lib/python3.5/site-packages/_pytest/config.py:361: in _importconftest return self._conftestpath2mod[conftestpath] E KeyError: local('/home/nicolas/Projects/code/ch3/a/tasks_proj/tests/conftest.py') During handling of the above exception, another exception occurred: ../../.local/lib/python3.5/site-packages/_pytest/config.py:367: in _importconftest mod = conftestpath.pyimport() ../../.local/lib/python3.5/site-packages/py/_path/local.py:662: in pyimport __import__(modname) ../../.local/lib/python3.5/site-packages/_pytest/assertion/rewrite.py:216: in load_module py.builtin.exec_(co, mod.__dict__) ch3/a/tasks_proj/tests/conftest.py:2: in <module> import tasks E ImportError: No module named 'tasks' During handling of the above exception, another exception occurred: ../../.local/lib/python3.5/site-packages/py/_path/common.py:367: in visit for x in Visitor(fil, rec, ignore, bf, sort).gen(self): ../../.local/lib/python3.5/site-packages/py/_path/common.py:416: in gen for p in self.gen(subdir): ../../.local/lib/python3.5/site-packages/py/_path/common.py:416: in gen for p in self.gen(subdir): ../../.local/lib/python3.5/site-packages/py/_path/common.py:416: in gen for p in self.gen(subdir): ../../.local/lib/python3.5/site-packages/py/_path/common.py:405: in gen dirs = self.optsort([p for p in entries ../../.local/lib/python3.5/site-packages/py/_path/common.py:406: in <listcomp> if p.check(dir=1) and (rec is None or rec(p))]) ../../.local/lib/python3.5/site-packages/_pytest/main.py:687: in _recurse ihook = self.gethookproxy(path) ../../.local/lib/python3.5/site-packages/_pytest/main.py:591: in gethookproxy my_conftestmodules = pm._getconftestmodules(fspath) ../../.local/lib/python3.5/site-packages/_pytest/config.py:344: in _getconftestmodules mod = self._importconftest(conftestpath) ../../.local/lib/python3.5/site-packages/_pytest/config.py:369: in _importconftest raise ConftestImportFailure(conftestpath, sys.exc_info()) E _pytest.config.ConftestImportFailure: ImportError("No module named 'tasks'",) E File "/home/nicolas/.local/lib/python3.5/site-packages/_pytest/assertion/rewrite.py", line 216, in load_module E py.builtin.exec_(co, mod.__dict__) E File "/home/nicolas/Projects/code/ch3/a/tasks_proj/tests/conftest.py", line 2, in <module> E import tasks
Very sorry you are having difficulty. Thank you for including the stack trace.
It looks like you don’t have the tasks_proj installed.
cd /home/nicolas/Projects/code pip install ./tasks_proj pytest ch3/a/tasks_proj
I just re-read the start of chapter 3 and see that I don’t mention the need to install the tasks project. I did specify that in chapter 2. But I think in all the chapters that use the tasks project, I should remind people to install it first. It should be ok to skip around in chapters, or to only work through samples that are interesting without pre-requisites that aren’t listed.
I don’t know if that’s the case for you, I’m just saying it’s something I noticed after re-reading it.
Please let me know if that works or not, and thanks for writing in letting me know you are having issues.
You are right. Source code is working perfectly, now I’m on the chapter 4!, I learned a lot about pytest. Sorry for the post, I was wrong. Thanks.
Reading in progress: https://www.goodreads.com/book/show/34695799-python-testing-with-pytest
So glad it’s working for you now.