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
Automated testing tool developed in python for Advanced mathematical operations.

Advanced-Maths-Operations-Validations Automated testing tool developed in python for Advanced mathematical operations. Requirements Python 3.5 or late

Nikhil Repale 1 Nov 16, 2021
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
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
Data App Performance Tests

Data App Performance Tests My hypothesis is that The different architectures of

Marc Skov Madsen 6 Dec 14, 2022
Yet another python home automation project. Because a smart light is more than just on or off

Automate home Yet another home automation project because a smart light is more than just on or off. Overview When talking about home automation there

Maja Massarini 62 Oct 10, 2022
Hamcrest matchers for Python

PyHamcrest Introduction PyHamcrest is a framework for writing matcher objects, allowing you to declaratively define "match" rules. There are a number

Hamcrest 684 Dec 29, 2022
Mockoon is the easiest and quickest way to run mock APIs locally. No remote deployment, no account required, open source.

Mockoon Mockoon is the easiest and quickest way to run mock APIs locally. No remote deployment, no account required, open source. It has been built wi

mockoon 4.4k Dec 30, 2022
Mypy static type checker plugin for Pytest

pytest-mypy Mypy static type checker plugin for pytest Features Runs the mypy static type checker on your source files as part of your pytest test run

Dan Bader 218 Jan 03, 2023
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
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
Testing Calculations in Python, using OOP (Object-Oriented Programming)

Testing Calculations in Python, using OOP (Object-Oriented Programming) Create environment with venv python3 -m venv venv Activate environment . venv

William Koller 1 Nov 11, 2021
Fi - A simple Python 3.9+ command-line application for managing Fidelity portfolios

fi fi is a simple Python 3.9+ command-line application for managing Fidelity por

Darik Harter 2 Feb 26, 2022
Language-agnostic HTTP API Testing Tool

Dredd — HTTP API Testing Framework Dredd is a language-agnostic command-line tool for validating API description document against backend implementati

Apiary 4k Jan 05, 2023
splinter - python test framework for web applications

splinter - python tool for testing web applications splinter is an open source tool for testing web applications using Python. It lets you automate br

Cobra Team 2.6k Dec 27, 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
An AWS Pentesting tool that lets you use one-liner commands to backdoor an AWS account's resources with a rogue AWS account - or share the resources with the entire internet 😈

An AWS Pentesting tool that lets you use one-liner commands to backdoor an AWS account's resources with a rogue AWS account - or share the resources with the entire internet 😈

Brandon Galbraith 276 Mar 03, 2021
fsociety Hacking Tools Pack – A Penetration Testing Framework

Fsociety Hacking Tools Pack A Penetration Testing Framework, you will have every script that a hacker needs. Works with Python 2. For a Python 3 versi

Manisso 8.2k Jan 03, 2023
A cross-platform GUI automation Python module for human beings. Used to programmatically control the mouse & keyboard.

PyAutoGUI PyAutoGUI is a cross-platform GUI automation Python module for human beings. Used to programmatically control the mouse & keyboard. pip inst

Al Sweigart 7.5k Dec 31, 2022
Descriptor Vector Exchange

Descriptor Vector Exchange This repo provides code for learning dense landmarks without supervision. Our approach is described in the ICCV 2019 paper

James Thewlis 74 Nov 29, 2022
Python wrapper of Android uiautomator test tool.

uiautomator This module is a Python wrapper of Android uiautomator testing framework. It works on Android 4.1+ (API Level 16~30) simply with Android d

xiaocong 1.9k Dec 30, 2022