Closed ivanovmg closed 3 years ago
Thank for the PR, the solution is actually simpler, as in the book I meant to point to pyproject.toml. I will close this without merging but thanks for the contribution!
@lgiordani, I found that for me setup.py
was necessary anyway, to ensure that the package can be installed in an editable mode.
pip install -e .
Without this installed I cannot run pytest
locally - it fails because it cannot find package rentomatic
.
Once I install the package into the environment, pytest
works fine.
Isn't it the case for you?
@ivanovmg I see your point, and that's true, without setup.py
or setup.cfg
you can't install the package. OK, that makes sense, I'll add it to the code for completeness. As for pytest, however, you just need to create the correct __init__.py
both in rentomatic
and in tests
. Have you tried with the code downloaded from the repository? I just downloaded it, moved to ed2-c06-s05
and run pip install -r requirements/dev.txt
. After that I can run pytest -svv
.
I will review the code, in the meanwhile I reopened the PR. Thanks!
This is the list of commands I entered:
git clone https://github.com/pycabook/rentomatic.git
cd rentomatic/
python -m venv venv
source venv/Scripts/activate
pip install -r requirements/dev.txt
pytest -svv # <- at this stage it works fine
ls tests/
mkdir tests/domain
vim tests/domain/test_room.py # <- add first test
mkdir rentomatic
touch rentomatic/__init__.py
mkdir rentomatic/domain
vim rentomatic/domain/room.py # <- add implementation
pytest
Traceback:
============================= test session starts =============================
platform win32 -- Python 3.8.3, pytest-6.2.4, py-1.10.0, pluggy-0.13.1
rootdir: C:\Users\MIvanov4\temp\rentomatic, configfile: pytest.ini
plugins: cov-2.12.1
collected 0 items / 1 error
=================================== ERRORS ====================================
_________________ ERROR collecting tests/domain/test_room.py __________________
ImportError while importing test module 'C:\Users\ivanovmg\temp\rentomatic\tests\domain\test_room.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
..\..\AppData\Local\Programs\Python\Python38-32\lib\importlib\__init__.py:127: in import_module
return _bootstrap._gcd_import(name[level:], package, level)
tests\domain\test_room.py:2: in <module>
from rentomatic.domain.room import Room
E ModuleNotFoundError: No module named 'rentomatic'
=========================== short test summary info ===========================
ERROR tests/domain/test_room.py
!!!!!!!!!!!!!!!!!!! Interrupted: 1 error during collection !!!!!!!!!!!!!!!!!!!!
============================== 1 error in 0.18s ===============================
Good, this confirms what I thought. If you do not have the installed package you can run pytest
creating the file tests/__init__.py
and tests/domain/__init__.py
(check the repository, they are there). Can you try that? Thanks!
That said, I still think creating setup.cfg
is a good idea.
@lgiordani, once I added tests/domain/__init__.py
it started working!
There is a file tests/__init__.py
in the repo, so I though this would be enough.
Apparently, it is necessary to create __init__.py
for any test subproject, even if there are no names collision.
Thank you for the hint!
This has been solved in the latest version of the book (2.1.0) and in the code. Thanks!
Add minimal
setup.py
Fixes https://github.com/pycabook/pycabook/issues/51