Code Monkey home page Code Monkey logo

pytest-watcher's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

pytest-watcher's Issues

Can't ignore ".venv/"

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

  • `ptw . --ignore_patterns ".venv/"
  • `ptw . --ignore_patterns ".venv/*"
  • `ptw . --ignore_patterns ".venv*"

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.

Interactive mode

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:

  • Ability to cancel a test run
  • Ability to specify a filename to match (including globs like foo/**/bar)
  • Ability to specify a test name to match (I believe this matches across all files, and can be used in conjunction with the previous)

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.

`--patterns` option being passed to `pytest`

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

Broken on 0.4.0 on Windows: Termios is not on windows

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>

`ptw` should call ptw on current directory

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.

emit_trigger() should trigger when a file moved to a destination under watch

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()

Not able to use pytest_watcher along with VS Code debugpy

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 have this configuration setup to run debug mode on a opened file:

Screenshot from 2024-02-21 09-30-57

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:

  • If I set "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.
  • If I set "console": "externalTerminal" or just let the last config without activating my venv it stops inside ptw script and raises the following error:

Screenshot from 2024-02-21 09-24-31

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.

  • VS Code: 1.86.2
  • Python: 3.11.7
  • Pytest: 8.0.1 (but the same thing was happening with 7.4.0)
  • Pytest-watcher: 0.4.1
  • Debugpy Extension: 2024.0.0

This is the code snippet I'm trying to debug:

image

Some other plugins I use along Pytest:

image


Some of the things I've tried

  • The obvious: remade my venv folder.
  • Absolute path to all configs (program, python, cwd, etc.)
  • Removed coverage report in addopts section in pytest.ini file or by env variable.
  • Changed my workspace default interpreter.

Option to run on start

Thank you for the project

#1

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)

Offer option to clear screen after earch rerun

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!!

Ability to run only certain tests

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.

Auto-Run?

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

Higher test latency than pytest-watch

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)

@RB387

How could the test latency be reduced?

CHANGELOG file?

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 😄

Support other executables than `pytest`

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.

pip dep is required but not declared

➜  ~/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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.