Open remcohaszing opened 8 years ago
Since I've updated to 4.0.0 this no longer works.
Please elaborate: what does not work anymore?
I have installed pytest-watch using
$ pip install --user pytest-watch
$ which ptw
/home/remco/.local/bin/ptw
Now if I create a virtualenv, install requirements in that virtualenv and then run ptw
, the tests will fail because of import errors.
$ mktmpenv
...
(tmp-55b2a2e395dca7) $ pip install flask
Error: Could not run --collect-only to find the pytest config file. Trying again without silencing stdout...
...
ImportError: No module named 'flask'
ERROR: could not load /home/remco/someproject/tests/conftest.py
However, when downgrading pytest-watch to ~2.0.0
, I can run this just fine.
$ pip install --user -U 'pytest-watch~=2.0.0' # outside of virtualenv
Then in the virtualenv again:
(tmp-55b2a2e395dca7) $ ptw
=== test session starts ===
platform linux -- Python 3.5.1+, pytest-2.9.1, py-1.4.31, pluggy-0.3.1
rootdir: /home/remco/someproject, inifile:
collected 1 item
tests/test_spam.py .
=== 1 passed in 0.01 seconds ===
Sorry for the late reaction.
I have the same issue. This tool looks useful, I installed it via pipx because I only want one copy.
I thought the --runner
option would solve my problem, but it does not. The program appears to import code directly rather than just executing the runner arg when files change.
Maybe I'm not using it correctly. Running pytest (which has been installed in the virtual env) works, but running ptw from outside does not work. (fish shell in example below)
$ ptw -v --runner (which pytest)
Locating inifile...
Error: Could not run --collect-only to handle the pytest config file. Trying again without silencing output...
ImportError while loading conftest '<redacted-path>/tests/conftest.py'.
tests/conftest.py:6: in <module>
from sqlalchemy.orm import sessionmaker
E ModuleNotFoundError: No module named 'sqlalchemy'
vs
$ pytest -v
================================================================================= test session starts ==================================================================================
platform linux -- Python 3.7.10, pytest-6.2.2, py-1.10.0, pluggy-0.13.1 -- <redacted-path>/bin/python
cachedir: .pytest_cache
rootdir: <redacted-path>
plugins: cov-2.11.1
collected 3 items
tests/test_organization.py::TestOrganization::test_add_invalid_organization PASSED [ 33%]
tests/test_organization.py::TestOrganization::test_add_update_get_organization PASSED [ 66%]
tests/test_organization.py::TestOrganization::test_list_organizations PASSED [100%
I'll also chip in and say that I have a virtualenv, I used poetry to install pytest
and pytest-watch
. pytest
works, pytest-watch
seems to have the wrong path when invoked directly:
>>> ptw
Error: Could not run --collect-only to handle the pytest config file. Trying again without silencing output...
ImportError while loading conftest '/home/myself/flask_layout/tests/conftest.py'.
tests/conftest.py:3: in <module>
from flask_layout import create_app
E ModuleNotFoundError: No module named 'flask_layout'
>>> python -m pytest-watch
/home/myself/.cache/pypoetry/virtualenvs/flask-layout-j2jffhM1-py3.10/bin/python: No module named pytest-watch
I have installed
pytest-watch
globally. I used to use this to runpy.test
from a virtual environment.Since I've updated to
4.0.0
this no longer works.As a workaround I now just install
pytest-watch
inside of the virtualenv as well, but I prefer not having to do so for each virtualenv.