Rerun pytest when your code changes

Overview

A simple watcher for pytest

PyPI PyPI - Python Version GitHub

Overview

pytest-watcher is a tool to automatically rerun pytest when your code changes. It looks for the following events:

  • New *.py file created
  • Existing *.py file modified
  • Existing *.py file deleted

What about pytest-watch?

pytest-watch was around for a long time and was solving exactly this problem. Sadly, pytest-watch is not maintained anymore and not working for many users. I wrote this tool as a substitute

Install pytest-watcher

pip install pytest-watcher

Usage

Specify the path that you want to watch:

ptw .

or

ptw /home/repos/project

Any arguments after <path> will be forwarded to pytest:

ptw . -x --lf --nf

Compatibility

The utility is OS independent and should be able to work with any platform.

Code is tested for Python versions 3.6+

Comments
  • Feature: Adds new CLI parameter `entrypoint`

    Feature: Adds new CLI parameter `entrypoint`

    Implements suggestion from this issue: https://github.com/olzhasar/pytest-watcher/issues/11

    The commits are rather dirty, please let me know if I should squash them.

    I only tested locally with Python 3.10 with the following parameters (using pip install -e .)

    ptw .
    ptw . --now
    ptw . --now --entrypoint tox
    ptw . --entrypoint tox
    
    opened by paolorechia 5
  • emit_trigger() should trigger when a file moved to a destination under watch

    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()
    
    opened by bob-rove 3
  • Option to run on start

    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)

    opened by tony 3
  • CHANGELOG file?

    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 😄

    opened by tony 2
  • Test on Python 3.10

    Test on Python 3.10

    Python 3.10 was released on 2021-10-04:

    • https://discuss.python.org/t/python-3-10-0-is-now-available/10955
    $ tox -e py310
    .package create: /private/tmp/pytest-watcher/.tox/.package
    .package installdeps: poetry-core>=1.0.0
    py310 create: /private/tmp/pytest-watcher/.tox/py310
    py310 installdeps: watchdog, pytest, pytest-mock, freezegun
    py310 inst: /private/tmp/pytest-watcher/.tox/.tmp/package/1/pytest-watcher-0.2.1.tar.gz
    py310 installed: attrs==21.2.0,freezegun==1.1.0,iniconfig==1.1.1,packaging==21.3,pluggy==1.0.0,py==1.11.0,pyparsing==3.0.6,pytest==6.2.5,pytest-mock==3.6.1,pytest-watcher @ file:///private/tmp/pytest-watcher/.tox/.tmp/package/1/pytest-watcher-0.2.1.tar.gz,python-dateutil==2.8.2,six==1.16.0,toml==0.10.2,watchdog==2.1.6
    py310 run-test-pre: PYTHONHASHSEED='546577221'
    py310 run-test: commands[0] | pytest
    ========================================================== test session starts ===========================================================
    platform darwin -- Python 3.10.1, pytest-6.2.5, py-1.11.0, pluggy-1.0.0
    cachedir: .tox/py310/.pytest_cache
    rootdir: /private/tmp/pytest-watcher
    plugins: mock-3.6.1
    collected 21 items
    
    tests/test_pytest_watcher.py .....................                                                                                 [100%]
    
    =========================================================== 21 passed in 0.75s ===========================================================
    ________________________________________________________________ summary _________________________________________________________________
      py310: commands succeeded
      congratulations :)
    
    opened by hugovk 2
  • Auto-Run?

    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

    opened by KyleKing 2
  • Support other executables than `pytest`

    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.

    opened by paolorechia 1
  • `ptw` should call ptw on current directory

    `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.

    opened by thomasaarholt 1
  • Link badges to PyPI and the license

    Link badges to PyPI and the license

    So that clicking them takes you to PyPI and the license instead of just badge images.

    Preview:

    https://github.com/hugovk/pytest-watcher/blob/011962f6712170c4128d79b62a997adc4b5a1777/README.md

    opened by hugovk 1
  • Add non-py files watch support

    Add non-py files watch support

    Hello!

    Thank you very much for the simple and working pytest-watcher solution!

    I've missed a little functionality about filtering watch files above *.py. Because in my projects also .env and .ini files can widely change the behaviour.

    I added arguments to the command line now. In my case, it is okay as it. In future, we can also put some of these --include-filter and --ignore-filter arguments to the configuration file.

    And I also have small doubts about confusing examples. But for now, I have no idea how to make it more clear except documentation remark. https://github.com/olzhasar/pytest-watcher/compare/master...aptakhin:pytest-watcher:add-other-extensions-support#diff-58fb153a128d801a5a58c94d9fcd912af6349faa66d202cc43ec4e1c23ae25dfR54-R62

    opened by aptakhin 0
  • Offer option to clear screen after earch rerun

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

    enhancement question 
    opened by estevaoem 6
Releases(v0.2.6)
Owner
Olzhas Arystanov
Olzhas Arystanov
ApiPy was created for api testing with Python pytest framework which has also requests, assertpy and pytest-html-reporter libraries.

ApiPy was created for api testing with Python pytest framework which has also requests, assertpy and pytest-html-reporter libraries. With this f

Mustafa 1 Jul 11, 2022
Playwright Python tool practice pytest pytest-bdd screen-play page-object allure cucumber-report

pytest-ui-automatic Playwright Python tool practice pytest pytest-bdd screen-play page-object allure cucumber-report How to run Run tests execute_test

moyu6027 11 Nov 8, 2022
pytest plugin providing a function to check if pytest is running.

pytest-is-running pytest plugin providing a function to check if pytest is running. Installation Install with: python -m pip install pytest-is-running

Adam Johnson 21 Nov 1, 2022
Pytest-rich - Pytest + rich integration (proof of concept)

pytest-rich Leverage rich for richer test session output. This plugin is not pub

Bruno Oliveira 170 Dec 2, 2022
A pytest plugin to run an ansible collection's unit tests with pytest.

pytest-ansible-units An experimental pytest plugin to run an ansible collection's unit tests with pytest. Description pytest-ansible-units is a pytest

Community managed Ansible repositories 9 Dec 9, 2022
A pytest plugin, that enables you to test your code that relies on a running PostgreSQL Database

This is a pytest plugin, that enables you to test your code that relies on a running PostgreSQL Database. It allows you to specify fixtures for PostgreSQL process and client.

Clearcode 252 Dec 21, 2022
A pytest plugin that enables you to test your code that relies on a running Elasticsearch search engine

pytest-elasticsearch What is this? This is a pytest plugin that enables you to test your code that relies on a running Elasticsearch search engine. It

Clearcode 65 Nov 10, 2022
This is a pytest plugin, that enables you to test your code that relies on a running MongoDB database

This is a pytest plugin, that enables you to test your code that relies on a running MongoDB database. It allows you to specify fixtures for MongoDB process and client.

Clearcode 19 Oct 21, 2022
Set your Dynaconf environment to testing when running pytest

pytest-dynaconf Set your Dynaconf environment to testing when running pytest. Installation You can install "pytest-dynaconf" via pip from PyPI: $ pip

David Baumgold 3 Mar 11, 2022
a plugin for py.test that changes the default look and feel of py.test (e.g. progressbar, show tests that fail instantly)

pytest-sugar pytest-sugar is a plugin for pytest that shows failures and errors instantly and shows a progress bar. Requirements You will need the fol

Teemu 963 Dec 28, 2022
This is a simple software for fetching new changes to remote repositories automatically.

Git Autofetch Git Autofetch is a simple software for fetching new changes from a repo to local repositories after a set time interval. This program is

Shreyas Ashtamkar 10 Jul 21, 2022
A Django plugin for pytest.

Welcome to pytest-django! pytest-django allows you to test your Django project/applications with the pytest testing tool. Quick start / tutorial Chang

pytest-dev 1.1k Dec 31, 2022
A set of pytest fixtures to test Flask applications

pytest-flask An extension of pytest test runner which provides a set of useful tools to simplify testing and development of the Flask extensions and a

pytest-dev 433 Dec 23, 2022
A command-line tool and Python library and Pytest plugin for automated testing of RESTful APIs, with a simple, concise and flexible YAML-based syntax

1.0 Release See here for details about breaking changes with the upcoming 1.0 release: https://github.com/taverntesting/tavern/issues/495 Easier API t

null 909 Dec 15, 2022
pytest splinter and selenium integration for anyone interested in browser interaction in tests

Splinter plugin for the pytest runner Install pytest-splinter pip install pytest-splinter Features The plugin provides a set of fixtures to use splin

pytest-dev 238 Nov 14, 2022
The pytest framework makes it easy to write small tests, yet scales to support complex functional testing

The pytest framework makes it easy to write small tests, yet scales to support complex functional testing for applications and libraries. An example o

pytest-dev 9.6k Jan 2, 2023
Coverage plugin for pytest.

Overview docs tests package This plugin produces coverage reports. Compared to just using coverage run this plugin does some extras: Subprocess suppor

pytest-dev 1.4k Dec 29, 2022
Thin-wrapper around the mock package for easier use with pytest

pytest-mock This plugin provides a mocker fixture which is a thin-wrapper around the patching API provided by the mock package: import os class UnixF

pytest-dev 1.5k Jan 5, 2023
pytest plugin for distributed testing and loop-on-failures testing modes.

xdist: pytest distributed testing plugin The pytest-xdist plugin extends pytest with some unique test execution modes: test run parallelization: if yo

pytest-dev 1.1k Dec 30, 2022