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
pywinauto is a set of python modules to automate the Microsoft Windows GUI

pywinauto is a set of python modules to automate the Microsoft Windows GUI. At its simplest it allows you to send mouse and keyboard actions to windows dialogs and controls, but it has support for mo

3.8k Jan 06, 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 wrapper for webdriver that is a jumping off point for web automation.

Webdriver Automation Plus ===================================== Description: Tests the user can save messages then find them in search and Saved items

1 Nov 08, 2021
Free cleverbot without headless browser

Cleverbot Scraper Simple free cleverbot library that doesn't require running a heavy ram wasting headless web browser to actually chat with the bot, a

Matheus Fillipe 3 Sep 25, 2022
Switch among Guest VMs organized by Resource Pool

Proxmox PCI Switcher Switch among Guest VMs organized by Resource Pool. main features: ONE GPU card, N OS (at once) Guest VM command client Handler po

Rosiney Gomes Pereira 111 Dec 27, 2022
Travel through time in your tests.

time-machine Travel through time in your tests. A quick example: import datetime as dt

Adam Johnson 373 Dec 27, 2022
Codeforces Test Parser for C/C++ & Python on Windows

Codeforces Test Parser for C/C++ & Python on Windows Installation Run pip instal

Minh Vu 2 Jan 05, 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
This repository has automation content to test Arista devices.

Network tests automation Network tests automation About this repository Requirements Requirements on your laptop Requirements on the switches Quick te

Netdevops Community 17 Nov 04, 2022
์ž๋™ ๊ฑด๊ฐ•์ƒํƒœ ์ž๊ฐ€์ง„๋‹จ ๋ฉ”ํฌ๋กœ ์„œ๋ฒ„์ „์šฉ

Auto-Self-Diagnosis-for-server ์ž๋™ ์ž๊ฐ€์ง„๋‹จ ๋ฉ”ํฌ๋กœ ์„œ๋ฒ„์ „์šฉ ์ด ํ”„๋กœ๊ทธ๋žจ์€ SaidBySolo๋‹˜์˜ auto-self-diagnosis๋ฅผ ์ฐธ๊ณ ํ•˜์—ฌ ์ œ์ž‘ํ•˜์˜€์Šต๋‹ˆ๋‹ค. ๊ฐœ์ธ ์‚ฌ์šฉ ๋ชฉ์ ์œผ๋กœ ์ œ์ž‘ํ•˜์˜€๊ธฐ ๋•Œ๋ฌธ์— ์ถ”ํ›„ ์—…๋ฐ์ดํŠธ๋Š” ์ง„ํ–‰ํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค. ์˜์กด์„ฑ G

JJooni 3 Dec 04, 2021
Automated Security Testing For REST API's

Astra REST API penetration testing is complex due to continuous changes in existing APIs and newly added APIs. Astra can be used by security engineers

Flipkart Incubator 2.1k Dec 31, 2022
PENBUD is penetration testing buddy which helps you in penetration testing by making various important tools interactive.

penbud - Penetration Tester Buddy PENBUD is penetration testing buddy which helps you in penetration testing by making various important tools interac

Himanshu Shukla 15 Feb 01, 2022
A Library for Working with Sauce Labs

Robotframework - Sauce Labs Plugin This is a plugin for the SeleniumLibrary to help with using Sauce Labs. This library is a plugin extension of the S

joshin4colours 6 Oct 12, 2021
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 Modular Penetration Testing Framework

fsociety A Modular Penetration Testing Framework Install pip install fsociety Update pip install --upgrade fsociety Usage usage: fsociety [-h] [-i] [-

fsociety-team 802 Dec 31, 2022
Tools for test driven data-wrangling and data validation.

datatest: Test driven data-wrangling and data validation Datatest helps to speed up and formalize data-wrangling and data validation tasks. It impleme

269 Dec 16, 2022
UX Analytics & A/B Testing

UX Analytics & A/B Testing

Marvin EDORH 1 Sep 07, 2021
Multi-asset backtesting framework. An intuitive API lets analysts try out their strategies right away

Multi-asset backtesting framework. An intuitive API lets analysts try out their strategies right away. Fast execution of profit-take/loss-cut orders is built-in. Seamless with Pandas.

Epymetheus 39 Jan 06, 2023
Doing dirty (but extremely useful) things with equals.

Doing dirty (but extremely useful) things with equals. Documentation: dirty-equals.helpmanual.io Source Code: github.com/samuelcolvin/dirty-equals dir

Samuel Colvin 602 Jan 05, 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