olzhasar / pytest-watcher Goto Github PK
View Code? Open in Web Editor NEWAutomatically rerun your tests on file modifications
License: MIT License
Automatically rerun your tests on file modifications
License: MIT License
Just discovered this tool, looks very cool! Thanks for developing it!
I'm running ptw .
and I want to ignore any changes in my virtualenv (installed at .venv/
in the project root).
I've tried
but none of them work.
I think I have identified the issue. In watcher.py
in _is_event_watched
there is call to match_any_paths
.
In match_any_paths
, case_sensitive
is an optional keyword, but it defaults to True. I'm on a Windows machine, so all my paths are being converted to a PurePosixPath
.
Please see #29
Building on this, I'd love to see some sort of interactive mode built into pytest-watcher
.
For inspiration, I've used tools such as jest and vitest from the Javascript world, which both offer something similar to what I'm describing. Their feature sets (off the top of my head) include:
foo/**/bar
)There may be others that I'm forgetting.
I would love to see even a subset - say, just the ability to specify filenames interactively - offered. While it's great that we can forward arguments to pytest
(as described here), I think it would be even more powerful and TDD-supportive to interact with the tool without having to restart pytest-watcher
to respecify filenames.
Based on the README I'd expect ptw . --patterns '*.*' .
to watch all filetypes. Instead, the patterns
argument is getting passed to pytest and the command fails with the following:
ERROR: usage: pytest [options] [file_or_dir] [file_or_dir] [...]
pytest: error: unrecognized arguments: --patterns
Hey there, refugee from pytest-watch.
https://docs.python.org/3/library/termios.html
PS C:\Users\Kaine> ptw .
Traceback (most recent call last):
File "<frozen runpy>", line 198, in _run_module_as_main
File "<frozen runpy>", line 88, in _run_code
File "C:\Users\Kaine\AppData\Local\Programs\Python\Python311\Scripts\ptw.exe\__main__.py", line 4, in <module>
File "C:\Users\Kaine\AppData\Local\Programs\Python\Python311\Lib\site-packages\pytest_watcher\__init__.py", line 1, in <module>
from .watcher import VERSION, run
File "C:\Users\Kaine\AppData\Local\Programs\Python\Python311\Lib\site-packages\pytest_watcher\watcher.py", line 10, in <module>
from . import commands
File "C:\Users\Kaine\AppData\Local\Programs\Python\Python311\Lib\site-packages\pytest_watcher\commands.py", line 8, in <module>
from .terminal import Terminal
File "C:\Users\Kaine\AppData\Local\Programs\Python\Python311\Lib\site-packages\pytest_watcher\terminal.py", line 6, in <module>
import termios
ModuleNotFoundError: No module named 'termios'
PS C:\Users\Kaine>
Could you default path
to .
when it's not informed?
So calling ptw
or ptw .
(as described in the README) would do the same thing.
Reasoning: it will be easier to upgrade from pytest-watch.
Most calls I've seen are like ptw -- <some args passed to pytest>
.
Hi! Thanks for forking ptw and continuing it!
Since you've released pytest–watcher on pypi, automatic workflows are now picking your package over the old one, which is mostly great. Unfortunately, ptw could previously be run on the present working directory by calling ptw
without options. The new version breaks this backward compatibility.
Unless you have very good reason to do, I suggest you re-introduce this behaviour.
The issue appears when performing a file move operation from not watched to a watched destination.
Expected behaviour: if destination file path in move operation appears to be watched (while source file path is not), pytest-watcher
should trigger pytest
.
Here is an example of events appearing when using unison tool, which is syncing changes to remote destination by first creating a temporary file and then renaming it to a destination:
2022-10-17 15:32:18 - Created file: ./tests/sites/.unison.test_discover.py.7f0384dc585055b3fcfb405908d8de58.unison.tmp
2022-10-17 15:32:18 - Modified directory: ./tests/sites
2022-10-17 15:32:18 - Modified file: ./tests/sites/.unison.test_discover.py.7f0384dc585055b3fcfb405908d8de58.unison.tmp
2022-10-17 15:32:18 - Modified directory: ./tests/sites
2022-10-17 15:32:18 - Modified file: ./tests/sites/.unison.test_discover.py.7f0384dc585055b3fcfb405908d8de58.unison.tmp
2022-10-17 15:32:18 - Moved file: from ./tests/sites/.unison.test_discover.py.7f0384dc585055b3fcfb405908d8de58.unison.tmp to ./tests/sites/test_discover.py
2022-10-17 15:32:18 - Modified directory: ./tests/sites
These events gathered with watchdog
example code here: https://pypi.org/project/watchdog/
The fix seems to be pretty straightforward - just extend the condition in process_event method to something like this:
def process_event(self, event: events.FileSystemEvent) -> None:
if _is_path_watched(event.src_path):
emit_trigger()
elif event.event_type == events.EVENT_TYPE_MOVED and _is_path_watched(event.dest_path):
emit_trigger()
Hello guys... I'm not sure if this issue should be assigned here, but since watcher is the only thing that is raising something when trying to debug tests I think it is in the right place.
I'm trying to run VS Code debug mode along with watcher but I'm getting some annoying errors. I had set this debug config above to run pytest_watcher in debug mode but it has some different behaviors for some scenarios:
"console": "integratedTerminal"
, it only works if I activate a virtual environment in an already opened console before running the debug mode but it skips all breakpoints."console": "externalTerminal"
or just let the last config without activating my venv it stops inside ptw script and raises the following error:I'm opting to use the old pytest-watch for debug mode. It is working just fine. If I switch to simple python debug configuration type ( "type": "python"
), it runs fine but it skips all breakpoints. Opting to use debugpy because the simple one will be deprecated soon.
Thank you for the project
It'd be nice to have an option / flag for this. I am duplicating running the tests automatically by having to write 2 commands with the same files listed (one for py.test
, one for ptw
)
My project is organized as:
src/
tests/
<all sorts of crap in many folders>
Could I potentially do
ptw src/ tests/
instead of ignoring all the stuff I don't care about.
Hello @olzhasar. First of all, thanks for your contribution, its really handy.
I'd suggest a little modification at the function
def _run_pytest(args) -> None:
subprocess.run(["pytest", *args])
To something like
def _run_pytest(args, clear=False) -> None:
if clear:
subprocess.run(["clear"])
subprocess.run(["pytest", *args])
To clear the results before each test.
Thanks!!
Hi. Thanks for the awesome package.
Maybe I am missing some functionality here, but I would love to be able to watch certain files AND run certain tests (and implicitly watch any changes to those tests). Maybe something like:
# Tests trigger if I edit tests/db_example.py or src/db_connection.py
ptw --tests tests/db*.py src/db*.py
pytest-watch
's documentation suggest it allowed to pass arguments to pytest
with something like the following, but I haven't tried it.
ptw src/db*.py -- tests/db*.py
Right now, I can limit what triggers a test run, but it runs all the tests, which can take significant time depending on the codebase.
Would you consider making pytest-watcher
run right away rather than waiting for changes?
I find that I often end up adding and deleting lines to trigger the first run
We are migrating from pytest-watch
to pytest-watcher
and noticed considerable latency when making code changes.
I tried to debug the pytest-watcher code. In fact, both of them use the same library to track files change events - watchdog. And it seems that pytest-watcher catches such events almost immediately, but most of the time it waits for `subprocess.run' (to run tests)
How could the test latency be reduced?
Is it possible we can have a changelog file to see releases over time w/o GitHub releases?
The reason why is I think changelog files are the easier way to see changes. I feel GitHub releases adds distractions/walls/barriers that make it more frustrating to catch up with the changes 😄
Given somewhat complex argument handling, if you were willing to take a dependency on click
code would get easier. Let me know if you are open to that, can send you a PR.
Hi, this looks like an interesting package, I've tested it locally on a stub project and it seems to work fine, nice work.
However, I've worked with real projects that are tied to other tooling besides pytest
, for instance, tox
, make
or even just bash scripts (which in turn, execute pytest with a particular setup).
A really useful feature IMO would be to add an argument to the CLI, to override your entry point executable, so we can hook the watcher with other executables (though, I guess that partially defeats the purpose of naming this package pytest-watcher
😄 ).
What are your thoughts on it? Worth implementing? I'd be happy to work on a PR for this if you agree with it.
➜ ~/s/peated (feat/rewrite-api-in-python) ✗ ptw
Traceback (most recent call last):
File "/home/dcramer/src/peated/.venv/lib/python3.11/site-packages/pytest_watcher/config.py", line 9, in <module>
import tomlib
ModuleNotFoundError: No module named 'tomlib'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/dcramer/src/peated/.venv/bin/ptw", line 5, in <module>
from pytest_watcher import run
File "/home/dcramer/src/peated/.venv/lib/python3.11/site-packages/pytest_watcher/__init__.py", line 1, in <module>
from .watcher import VERSION, run
File "/home/dcramer/src/peated/.venv/lib/python3.11/site-packages/pytest_watcher/watcher.py", line 15, in <module>
from .config import Config
File "/home/dcramer/src/peated/.venv/lib/python3.11/site-packages/pytest_watcher/config.py", line 11, in <module>
from pip._vendor import tomli as tomlib
ModuleNotFoundError: No module named 'pip'
This is in a pdm-based project. May operate diff than poetry and some other mechanisms.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.