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
a wrapper around pytest for executing tests to look for test flakiness and runtime regression

bubblewrap a wrapper around pytest for assessing flakiness and runtime regressions a cs implementations practice project How to Run: First, install de

Anna Nagy 1 Aug 05, 2021
A utility for mocking out the Python Requests library.

Responses A utility library for mocking out the requests Python library. Note Responses requires Python 2.7 or newer, and requests = 2.0 Installing p

Sentry 3.8k Jan 03, 2023
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 02, 2022
Test utility for validating OpenAPI documentation

DRF OpenAPI Tester This is a test utility to validate DRF Test Responses against OpenAPI 2 and 3 schema. It has built-in support for: OpenAPI 2/3 yaml

snok 103 Dec 21, 2022
Main purpose of this project is to provide the service to automate the API testing process

PPTester project Main purpose of this project is to provide the service to automate the API testing process. In order to deploy this service use you s

4 Dec 16, 2021
Redis fixtures and fixture factories for Pytest.

Redis fixtures and fixture factories for Pytest.This is a pytest plugin, that enables you to test your code that relies on a running Redis database. It allows you to specify additional fixtures for R

Clearcode 86 Dec 23, 2022
模仿 USTC CAS 的程序,用于开发校内网站应用的本地调试。

ustc-cas-mock 模仿 USTC CAS 的程序,用于开发校内网站应用阶段调试。 请勿在生产环境部署! 只测试了最常用的三个 CAS route: /login /serviceValidate(验证 CAS ticket) /logout 没有测试过 proxy ticket。(因为我

taoky 4 Jan 27, 2022
WomboAI Art Generator

WomboAI Art Generator Automate AI art generation using wombot.art. Also integrated into SnailBot for you to try out. Setup Install Python Go to the py

nbee 7 Dec 03, 2022
Generic automation framework for acceptance testing and RPA

Robot Framework Introduction Installation Example Usage Documentation Support and contact Contributing License Introduction Robot Framework is a gener

Robot Framework 7.7k Jan 07, 2023
Nokia SR OS automation

Nokia SR OS automation Nokia is one of the biggest vendors of the telecommunication equipment, which is very popular in the Service Provider segment.

Karneliuk.com 7 Jul 23, 2022
A configurable set of panels that display various debug information about the current request/response.

Django Debug Toolbar The Django Debug Toolbar is a configurable set of panels that display various debug information about the current request/respons

Jazzband 7.3k Jan 02, 2023
Load and performance benchmark tool

Yandex Tank Yandextank has been moved to Python 3. Latest stable release for Python 2 here. Yandex.Tank is an extensible open source load testing tool

Yandex 2.2k Jan 03, 2023
Selenium-python but lighter: Helium is the best Python library for web automation.

Selenium-python but lighter: Helium Selenium-python is great for web automation. Helium makes it easier to use. For example: Under the hood, Helium fo

Michael Herrmann 3.2k Dec 31, 2022
A tool to auto generate the basic mocks and asserts for faster unit testing

Mock Generator A tool to generate the basic mocks and asserts for faster unit testing. 🎉 New: you can now use pytest-mock-generator, for more fluid p

31 Dec 24, 2022
reCaptchaBypasser For Bypass Any reCaptcha For Selenium Python

reCaptchaBypasser ' Usage : from selenium import webdriver from reCaptchaBypasser import reCaptchaScraper import time driver = webdriver.chrome(execu

Dr.Linux 8 Dec 17, 2022
A suite of benchmarks for CPU and GPU performance of the most popular high-performance libraries for Python :rocket:

A suite of benchmarks for CPU and GPU performance of the most popular high-performance libraries for Python :rocket:

Dion Häfner 255 Jan 04, 2023
Cornell record & replay mock server

Cornell: record & replay mock server Cornell makes it dead simple, via its record and replay features to perform end-to-end testing in a fast and isol

HiredScoreLabs 134 Sep 15, 2022
Pyramid debug toolbar

pyramid_debugtoolbar pyramid_debugtoolbar provides a debug toolbar useful while you're developing your Pyramid application. Note that pyramid_debugtoo

Pylons Project 95 Sep 17, 2022
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
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