pytest-watch


Namepytest-watch JSON
Version 4.2.0 PyPI version JSON
download
home_pagehttp://github.com/joeyespo/pytest-watch
SummaryLocal continuous test runner with pytest and watchdog.
upload_time2018-05-20 19:52:16
maintainer
docs_urlNone
authorJoe Esposito
requires_python
licenseMIT
keywords
VCS
bugtrack_url
requirements docopt colorama watchdog pytest
Travis-CI No Travis.
coveralls test coverage No coveralls.
            pytest-watch – Continuous pytest runner
=======================================

`Current version on PyPI <http://pypi.python.org/pypi/pytest-watch/>`__
`Say Thanks! <https://saythanks.io/to/joeyespo>`__

**pytest-watch** a zero-config CLI tool that runs
`pytest <http://pytest.org/>`__, and re-runs it when a file in your
project changes. It beeps on failures and can run arbitrary commands on
each passing and failing test run.

Motivation
----------

Whether or not you use the test-driven development method, running tests
continuously is far more productive than waiting until you’re finished
programming to test your code. Additionally, manually running
``py.test`` each time you want to see if any tests were broken has more
wait-time and cognitive overhead than merely listening for a
notification. This could be a crucial difference when debugging a
complex problem or on a tight deadline.

Installation
------------

.. code:: bash

   $ pip install pytest-watch

Usage
-----

.. code:: bash

   $ cd myproject
   $ ptw
    * Watching /path/to/myproject

*Note: It can also be run using its full name ``pytest-watch``.*

Now develop normally and check the terminal every now and then to see if
any tests are broken. Alternatively, pytest-watch can **notify you**
when tests pass or fail:

-  **OSX**

   ``$ ptw --onpass "say passed" --onfail "say failed"``

   .. code:: bash

      $ ptw --onpass "growlnotify -m \"All tests passed!\"" \
            --onfail "growlnotify -m \"Tests failed\""

   using `GrowlNotify <http://growl.info/downloads#generaldownloads>`__.

-  **Windows**

   .. code:: bat

      > ptw --onfail flash

   using `Console Flash <http://github.com/joeyespo/console-flash>`__

You can also run a command before the tests run, e.g. seeding your test
database:

.. code:: bash

   $ ptw --beforerun init_db.py

Or after they finish, e.g. deleting a sqlite file. Note that this script
receives the exit code of ``py.test`` as an argument.

.. code:: bash

   $ ptw --afterrun cleanup_db.py

You can also use a custom runner script for full ``py.test`` control:

.. code:: bash

   $ ptw --runner "python custom_pytest_runner.py"

Here’s an minimal runner script that runs ``py.test`` and prints its
exit code:

.. code:: py

   # custom_pytest_runner.py

   import sys
   import pytest

   print('py.test exited with code:', pytest.main(sys.argv[1:]))

Need to exclude directories from being observed or collected for tests?

.. code:: bash

   $ ptw --ignore ./deep-directory --ignore ./integration_tests

See the full list of options:

::

   $ ptw --help
   Usage: ptw [options] [--ignore <dir>...] [<directory>...] [-- <pytest-args>...]

   Options:
     --ignore <dir>        Ignore directory from being watched and during
                           collection (multi-allowed).
     --ext <exts>          Comma-separated list of file extensions that can
                           trigger a new test run when changed (default: .py).
                           Use --ext=* to allow any file (including .pyc).
     --config <file>       Load configuration from `file` instead of trying to
                           locate one of the implicit configuration files.
     -c --clear            Clear the screen before each run.
     -n --nobeep           Do not beep on failure.
     -w --wait             Waits for all tests to complete before re-running.
                           Otherwise, tests are interrupted on filesystem events.
     --beforerun <cmd>     Run arbitrary command before tests are run.
     --afterrun <cmd>      Run arbitrary command on completion or interruption.
                           The exit code of "py.test" is passed as an argument.
     --onpass <cmd>        Run arbitrary command on pass.
     --onfail <cmd>        Run arbitrary command on failure.
     --onexit <cmd>        Run arbitrary command when exiting pytest-watch.
     --runner <cmd>        Run a custom command instead of "py.test".
     --pdb                 Start the interactive Python debugger on errors.
                           This also enables --wait to prevent pdb interruption.
     --spool <delay>       Re-run after a delay (in milliseconds), allowing for
                           more file system events to queue up (default: 200 ms).
     -p --poll             Use polling instead of OS events (useful in VMs).
     -v --verbose          Increase verbosity of the output.
     -q --quiet            Decrease verbosity of the output (precedence over -v).
     -V --version          Print version and exit.
     -h --help             Print help and exit.

Configuration
-------------

CLI options can be added to a ``[pytest-watch]`` section in your
`pytest.ini file <https://pytest.org/latest/customize.html>`__ to
persist them in your project. For example:

.. code:: ini

   # pytest.ini

   [pytest]
   addopts = --maxfail=2


   [pytest-watch]
   ignore = ./integration-tests
   nobeep = True

Alternatives
------------

-  `xdist <http://pypi.python.org/pypi/pytest-xdist>`__ offers the
   ``--looponfail`` (``-f``) option (and distributed testing options).
   This instead re-runs only those tests which have failed until you
   make them pass. This can be a speed advantage when trying to get all
   tests passing, but leaves out the discovery of new failures until
   then. It also drops the colors outputted by py.test, whereas
   pytest-watch doesn’t.
-  `Nosey <http://github.com/joeyespo/nosey>`__ is the original codebase
   this was forked from. Nosey runs
   `nose <http://nose.readthedocs.org/en/latest/>`__ instead of pytest.

Contributing
------------

1. Check the open issues or open a new issue to start a discussion
   around your feature idea or the bug you found
2. Fork the repository, make your changes, and add yourself to
   `Authors.md <./AUTHORS.md>`__
3. Send a pull request

If you want to edit the README, be sure to make your changes to
``README.md`` and run the following to regenerate the ``README.rst``
file:

.. code:: bash

   $ pandoc -t rst -o README.rst README.md

If your PR has been waiting a while, feel free to `ping me on
Twitter <https://twitter.com/joeyespo>`__.

Use this software often? :smiley:

            

Raw data

            {
    "_id": null,
    "home_page": "http://github.com/joeyespo/pytest-watch",
    "name": "pytest-watch",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "",
    "author": "Joe Esposito",
    "author_email": "joe@joeyespo.com",
    "download_url": "https://files.pythonhosted.org/packages/36/47/ab65fc1d682befc318c439940f81a0de1026048479f732e84fe714cd69c0/pytest-watch-4.2.0.tar.gz",
    "platform": "any",
    "description": "pytest-watch \u2013 Continuous pytest runner\n=======================================\n\n`Current version on PyPI <http://pypi.python.org/pypi/pytest-watch/>`__\n`Say Thanks! <https://saythanks.io/to/joeyespo>`__\n\n**pytest-watch** a zero-config CLI tool that runs\n`pytest <http://pytest.org/>`__, and re-runs it when a file in your\nproject changes. It beeps on failures and can run arbitrary commands on\neach passing and failing test run.\n\nMotivation\n----------\n\nWhether or not you use the test-driven development method, running tests\ncontinuously is far more productive than waiting until you\u2019re finished\nprogramming to test your code. Additionally, manually running\n``py.test`` each time you want to see if any tests were broken has more\nwait-time and cognitive overhead than merely listening for a\nnotification. This could be a crucial difference when debugging a\ncomplex problem or on a tight deadline.\n\nInstallation\n------------\n\n.. code:: bash\n\n   $ pip install pytest-watch\n\nUsage\n-----\n\n.. code:: bash\n\n   $ cd myproject\n   $ ptw\n    * Watching /path/to/myproject\n\n*Note: It can also be run using its full name ``pytest-watch``.*\n\nNow develop normally and check the terminal every now and then to see if\nany tests are broken. Alternatively, pytest-watch can **notify you**\nwhen tests pass or fail:\n\n-  **OSX**\n\n   ``$ ptw --onpass \"say passed\" --onfail \"say failed\"``\n\n   .. code:: bash\n\n      $ ptw --onpass \"growlnotify -m \\\"All tests passed!\\\"\" \\\n            --onfail \"growlnotify -m \\\"Tests failed\\\"\"\n\n   using `GrowlNotify <http://growl.info/downloads#generaldownloads>`__.\n\n-  **Windows**\n\n   .. code:: bat\n\n      > ptw --onfail flash\n\n   using `Console Flash <http://github.com/joeyespo/console-flash>`__\n\nYou can also run a command before the tests run, e.g.\u00a0seeding your test\ndatabase:\n\n.. code:: bash\n\n   $ ptw --beforerun init_db.py\n\nOr after they finish, e.g.\u00a0deleting a sqlite file. Note that this script\nreceives the exit code of ``py.test`` as an argument.\n\n.. code:: bash\n\n   $ ptw --afterrun cleanup_db.py\n\nYou can also use a custom runner script for full ``py.test`` control:\n\n.. code:: bash\n\n   $ ptw --runner \"python custom_pytest_runner.py\"\n\nHere\u2019s an minimal runner script that runs ``py.test`` and prints its\nexit code:\n\n.. code:: py\n\n   # custom_pytest_runner.py\n\n   import sys\n   import pytest\n\n   print('py.test exited with code:', pytest.main(sys.argv[1:]))\n\nNeed to exclude directories from being observed or collected for tests?\n\n.. code:: bash\n\n   $ ptw --ignore ./deep-directory --ignore ./integration_tests\n\nSee the full list of options:\n\n::\n\n   $ ptw --help\n   Usage: ptw [options] [--ignore <dir>...] [<directory>...] [-- <pytest-args>...]\n\n   Options:\n     --ignore <dir>        Ignore directory from being watched and during\n                           collection (multi-allowed).\n     --ext <exts>          Comma-separated list of file extensions that can\n                           trigger a new test run when changed (default: .py).\n                           Use --ext=* to allow any file (including .pyc).\n     --config <file>       Load configuration from `file` instead of trying to\n                           locate one of the implicit configuration files.\n     -c --clear            Clear the screen before each run.\n     -n --nobeep           Do not beep on failure.\n     -w --wait             Waits for all tests to complete before re-running.\n                           Otherwise, tests are interrupted on filesystem events.\n     --beforerun <cmd>     Run arbitrary command before tests are run.\n     --afterrun <cmd>      Run arbitrary command on completion or interruption.\n                           The exit code of \"py.test\" is passed as an argument.\n     --onpass <cmd>        Run arbitrary command on pass.\n     --onfail <cmd>        Run arbitrary command on failure.\n     --onexit <cmd>        Run arbitrary command when exiting pytest-watch.\n     --runner <cmd>        Run a custom command instead of \"py.test\".\n     --pdb                 Start the interactive Python debugger on errors.\n                           This also enables --wait to prevent pdb interruption.\n     --spool <delay>       Re-run after a delay (in milliseconds), allowing for\n                           more file system events to queue up (default: 200 ms).\n     -p --poll             Use polling instead of OS events (useful in VMs).\n     -v --verbose          Increase verbosity of the output.\n     -q --quiet            Decrease verbosity of the output (precedence over -v).\n     -V --version          Print version and exit.\n     -h --help             Print help and exit.\n\nConfiguration\n-------------\n\nCLI options can be added to a ``[pytest-watch]`` section in your\n`pytest.ini file <https://pytest.org/latest/customize.html>`__ to\npersist them in your project. For example:\n\n.. code:: ini\n\n   # pytest.ini\n\n   [pytest]\n   addopts = --maxfail=2\n\n\n   [pytest-watch]\n   ignore = ./integration-tests\n   nobeep = True\n\nAlternatives\n------------\n\n-  `xdist <http://pypi.python.org/pypi/pytest-xdist>`__ offers the\n   ``--looponfail`` (``-f``) option (and distributed testing options).\n   This instead re-runs only those tests which have failed until you\n   make them pass. This can be a speed advantage when trying to get all\n   tests passing, but leaves out the discovery of new failures until\n   then. It also drops the colors outputted by py.test, whereas\n   pytest-watch doesn\u2019t.\n-  `Nosey <http://github.com/joeyespo/nosey>`__ is the original codebase\n   this was forked from. Nosey runs\n   `nose <http://nose.readthedocs.org/en/latest/>`__ instead of pytest.\n\nContributing\n------------\n\n1. Check the open issues or open a new issue to start a discussion\n   around your feature idea or the bug you found\n2. Fork the repository, make your changes, and add yourself to\n   `Authors.md <./AUTHORS.md>`__\n3. Send a pull request\n\nIf you want to edit the README, be sure to make your changes to\n``README.md`` and run the following to regenerate the ``README.rst``\nfile:\n\n.. code:: bash\n\n   $ pandoc -t rst -o README.rst README.md\n\nIf your PR has been waiting a while, feel free to `ping me on\nTwitter <https://twitter.com/joeyespo>`__.\n\nUse this software often? :smiley:\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Local continuous test runner with pytest and watchdog.",
    "version": "4.2.0",
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "md5": "9f854cdf60212c5d1a210c8991619ba4",
                "sha256": "06136f03d5b361718b8d0d234042f7b2f203910d8568f63df2f866b547b3d4b9"
            },
            "downloads": -1,
            "filename": "pytest-watch-4.2.0.tar.gz",
            "has_sig": false,
            "md5_digest": "9f854cdf60212c5d1a210c8991619ba4",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 16340,
            "upload_time": "2018-05-20T19:52:16",
            "upload_time_iso_8601": "2018-05-20T19:52:16.194039Z",
            "url": "https://files.pythonhosted.org/packages/36/47/ab65fc1d682befc318c439940f81a0de1026048479f732e84fe714cd69c0/pytest-watch-4.2.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2018-05-20 19:52:16",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "joeyespo",
    "github_project": "pytest-watch",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [
        {
            "name": "docopt",
            "specs": [
                [
                    ">=",
                    "0.4.0"
                ]
            ]
        },
        {
            "name": "colorama",
            "specs": [
                [
                    ">=",
                    "0.3.3"
                ]
            ]
        },
        {
            "name": "watchdog",
            "specs": [
                [
                    ">=",
                    "0.6.0"
                ]
            ]
        },
        {
            "name": "pytest",
            "specs": [
                [
                    ">=",
                    "2.6.4"
                ]
            ]
        }
    ],
    "lcname": "pytest-watch"
}
        
Elapsed time: 0.01495s