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
frwk_51pwn is an open-sourced remote vulnerability testing and proof-of-concept development framework

frwk_51pwn Legal Disclaimer Usage of frwk_51pwn for attacking targets without prior mutual consent is illegal. frwk_51pwn is for security testing purp

51pwn 4 Apr 24, 2022
A simple script to login into twitter using Selenium in python.

Quick Talk A simple script to login into twitter using Selenium in python. I was looking for a way to login into twitter using Selenium in python. Sin

Lzy-slh 4 Nov 20, 2022
Avocado is a set of tools and libraries to help with automated testing.

Welcome to Avocado Avocado is a set of tools and libraries to help with automated testing. One can call it a test framework with benefits. Native test

Ana Guerrero Lopez 1 Nov 19, 2021
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
Fills out the container extension form automatically. (Specific to IIT Ropar)

automated_container_extension Fills out the container extension form automatically. (Specific to IIT Ropar) Download the chrome driver from the websit

Abhishek Singh Sambyal 1 Dec 24, 2021
Command line driven CI frontend and development task automation tool.

tox automation project Command line driven CI frontend and development task automation tool At its core tox provides a convenient way to run arbitrary

tox development team 3.1k Jan 04, 2023
hCaptcha solver and bypasser for Python Selenium. Simple website to try to solve hCaptcha.

hCaptcha solver for Python Selenium. Many thanks to engageub for his hCaptcha solver userscript. This script is solely intended for the use of educati

Maxime Dréan 59 Dec 25, 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
Automated Penetration Testing Framework

Automated Penetration Testing Framework

OWASP 2.1k Jan 01, 2023
A simple serverless create api test repository. Please Ignore.

serverless-create-api-test A simple serverless create api test repository. Please Ignore. Things to remember: Setup workflow Change Name in workflow e

Sarvesh Bhatnagar 1 Jan 18, 2022
模仿 USTC CAS 的程序,用于开发校内网站应用的本地调试。

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

taoky 4 Jan 27, 2022
Android automation project with pytest+appium

Android automation project with pytest+appium

1 Oct 28, 2021
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
A simple asynchronous TCP/IP Connect Port Scanner in Python 3

Python 3 Asynchronous TCP/IP Connect Port Scanner A simple pure-Python TCP Connect port scanner. This application leverages the use of Python's Standa

70 Jan 03, 2023
Wraps any WSGI application and makes it easy to send test requests to that application, without starting up an HTTP server.

WebTest This wraps any WSGI application and makes it easy to send test requests to that application, without starting up an HTTP server. This provides

Pylons Project 325 Dec 30, 2022
Faker is a Python package that generates fake data for you.

Faker is a Python package that generates fake data for you. Whether you need to bootstrap your database, create good-looking XML documents, fill-in yo

Daniele Faraglia 15.2k Jan 01, 2023
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
A Python Selenium library inspired by the Testing Library

Selenium Testing Library Slenium Testing Library (STL) is a Python library for Selenium inspired by Testing-Library. Dependencies Python 3.6, 3.7, 3.8

Anže Pečar 12 Dec 26, 2022
UUM Merit Form Filler is a web automation which helps automate entering a matric number to the UUM system in order for participants to obtain a merit

About UUM Merit Form Filler UUM Merit Form Filler is a web automation which helps automate entering a matric number to the UUM system in order for par

Ilham Rachmat 3 May 31, 2022
Pynguin, The PYthoN General UnIt Test geNerator is a test-generation tool for Python

Pynguin, the PYthoN General UnIt test geNerator, is a tool that allows developers to generate unit tests automatically.

Chair of Software Engineering II, Uni Passau 997 Jan 06, 2023