pytest-file-watcher


Namepytest-file-watcher JSON
Version 0.2.4 PyPI version JSON
download
home_pagehttps://github.com/deviljin112/Pytest-File-Watcher
SummaryPytest-File-Watcher is a CLI tool that watches for changes in your code and runs pytest on the changed files.
upload_time2023-03-23 22:29:23
maintainer
docs_urlNone
authorDeviljin112
requires_python>=3.9
licenseMIT
keywords python pytest testing testing-tools watch watcher
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Py Test Watch

Pytest-File-Watcher is a tool that watches your files and runs your pytest tests automatically when it detects changes.

## Why?

I was tired of running `pytest` manually every time I made a change to my code. I wanted a tool that would watch my files and run my tests automatically when it detected changes.
\
While [pytest-watch](https://github.com/joeyespo/pytest-watch) is a great tool, it is simply not maintained anymore. It works for most things, but I wanted something simpler. I wanted to be able to create config files within my projects so I dont need to remember all the flags and commands I need to pass to pytest. That way I just need to run `pytest-w test` and it will do all the work for me.
\
Pytest-File-Watcher may not have all the features of pytest-watch (**yet**), but I plan to expand the functionality of this tool as needed.
\
You will find that Pytest-File-Watcher is quite opinionated. It is designed to work with my workflow. If you have any suggestions, please feel free to open an issue or a pull request. I am always open to suggestions.
\
I hope it helps someone else with managing a multi-project testing workflow.

## Disclaimer

This tool is still in development. It's not perfect by any means. It does what I need it to do, but it may not work for your use case. Please feel free to open an issue or a pull request if you find any bugs or have any suggestions. I only tested so many use cases, so I am sure there are many more that I have not thought of.

## Installation

```bash
pip install Pytest-File-Watcher
```

## Usage

Main entrypoint

```bash
pytest-w
```

You can run the `--help` command to see all available options.

```bash
pytest-w --help
```

or on any command.

```bash
pytest-w test --help
```

You can also view the `--version` of the tool.

```bash
pytest-w --version
```

### Test Watching

I strongly recommend using the `config.yaml` file to configure Pytest-File-Watcher. You can use the `configure` command to generate a `config.yaml` (see [#Config](#config)) file in the root of your project or if you prefer writing it yourself see [#Config (Advanced)](#config-advanced) section. As mentioned before this is quite opinionated. I personally do not like to pass many flags and commands when testing. Especially when those flags don't change, but it can be problematic to navigate a long line of shell command to edit something. Hence **use the config**.
\
Anyway... The `test` command is the real reason you are here. It will watch your files and run your tests automatically when it detects changes. You need to pass the path to the folder you want to watch. You can just pass `./` to watch all files in the current directory.

```bash
pytest-w test ./path/to/folder
```

### Test Flags

There are many flags supported by Pytest-File-Watcher. You can pass them when using the `test` command. These flags take priority over the `config.yaml` file if used.
\
The flags are quite self-explanatory. I will list them here for convenience.
\
Verbose: `-v` or `--verbose`. Used when you want to see the full pytest output.
\
**Note:** If you want a more verbose pytest output use the `-p` flag instead.

```bash
pytest-w test ./path/to/folder -v
```

Auto Clear: `-a` or `--auto-clear`. Used when you want to clear the terminal after each test run.

```bash
pytest-w test ./path/to/folder -c
```

Config: `-c` or `--config`. Used when you want to pass a custom config file.

```bash
pytest-w test ./path/to/folder -c "path/to/config.yaml"
```

Ignore: `-i` or `--ignore`. Used when you want to ignore certain folders.

```bash
pytest-w test ./path/to/folder -i "venv" -i "node_modules"
```

Extensions: `-e` or `--extensions`. Used when you want to watch for extra file extensions.

```bash
pytest-w test ./path/to/folder -e ".py" -e ".txt"
```

Passthrough: `-p` or `--passthrough`. Used when you want to pass extra flags to pytest.

```bash
pytest-w test ./path/to/folder -t "-k" -t "test_something"
```

On Pass: `--on-pass`. Used when you want to run a shell command when all tests pass.

```bash
pytest-w test ./path/to/folder -p "echo 'All tests passed'"
```

On Fail: `--on-fail`. Used when you want to run a shell command when a test fails.

```bash
pytest-w test ./path/to/folder -f "echo 'A test has failed'"
```

### Config

If you are not familiar with yaml files, you can use this option to generate a `config.yaml` file in the root of your project.

```bash
pytest-w configure create
```

You can also edit the `config.yaml` file.

```bash
pytest-w configure edit
```

And view the current configuration.

```bash
pytest-w configure view
```

All above commands accept the `--config` flag to specify a custom config file. The default is the current working path.

```bash
pytest-w configure create --config "path/to/config.yaml"
```

### Config (Advanced)

Pytest-File-Watcher can be configured using a `config.yaml` file in the root of your project. Example of currently supported options:

```yaml
verbose: bool
autoClear: bool
onPass: shell-command
onFail: shell-command
extensions:
  - string-item
ignore:
  - string-item
passthrough:
  - string-item
  - string-item
```

See [example config](./example_config.yaml).
\
This will likely change in the future, and be expanded further. I will do my best to keep the documentation up-to-date.

### Recommendation

My daily driver is WSL2 within Windows 10. I have found myself running Pytest-File-Watcher in the background while doing other operations in another terminal tab and often forgetting to check the status of tests. I know that on linux you can use [notify-send](https://vaskovsky.net/notify-send/linux.html) to send notifications to your desktop. Well, on WSL you can use [wsl-notify-send](https://github.com/stuartleeks/wsl-notify-send) which essentially sends a notification to the Windows notification center. I have found this to be very useful and I highly recommend checking it out and using it in your own projects.
\
I have added the following to my `config.yaml` file:

```yaml
onPass: wsl-notify-send.exe --category "Pytest-File-Watcher" "All tests passed"
onFail: wsl-notify-send.exe --category "Pytest-File-Watcher" "A test has failed"
```

Now I can forget about Pytest-File-Watcher and it will notify me when it is done running tests. Not sure how this will work on other platforms, but I am sure there is a similar tool for MacOS.

## Manual Build

If you want to build the project manually, you can do so by cloning the repository. I recommend using a virtual environment.

```bash
python -m venv venv
source venv/bin/activate
```

Then install the dependencies.

```bash
pip install -r requirements.txt
```

And finally build the project.

```bash
pip install -e .
```

Then you can run the tool whenever you are in that virtual environment.

## Contributing

Contributions are welcome! Please feel free to open an issue or a pull request.

## Acknowledgements

- [pytest-watch](https://github.com/joeyespo/pytest-watch)
- [watchfiles](https://github.com/samuelcolvin/watchfiles)
- [typer](https://github.com/tiangolo/typer)

## Author

[Deviljin112](https://github.com/Deviljin112)

## License

MIT

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/deviljin112/Pytest-File-Watcher",
    "name": "pytest-file-watcher",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.9",
    "maintainer_email": "",
    "keywords": "python pytest testing testing-tools watch watcher",
    "author": "Deviljin112",
    "author_email": "",
    "download_url": "https://files.pythonhosted.org/packages/cd/d5/9bc4438e6eb681aee3b098b81f1d10a81d449e23fb662398b5ec97c163d6/pytest-file-watcher-0.2.4.tar.gz",
    "platform": null,
    "description": "# Py Test Watch\n\nPytest-File-Watcher is a tool that watches your files and runs your pytest tests automatically when it detects changes.\n\n## Why?\n\nI was tired of running `pytest` manually every time I made a change to my code. I wanted a tool that would watch my files and run my tests automatically when it detected changes.\n\\\nWhile [pytest-watch](https://github.com/joeyespo/pytest-watch) is a great tool, it is simply not maintained anymore. It works for most things, but I wanted something simpler. I wanted to be able to create config files within my projects so I dont need to remember all the flags and commands I need to pass to pytest. That way I just need to run `pytest-w test` and it will do all the work for me.\n\\\nPytest-File-Watcher may not have all the features of pytest-watch (**yet**), but I plan to expand the functionality of this tool as needed.\n\\\nYou will find that Pytest-File-Watcher is quite opinionated. It is designed to work with my workflow. If you have any suggestions, please feel free to open an issue or a pull request. I am always open to suggestions.\n\\\nI hope it helps someone else with managing a multi-project testing workflow.\n\n## Disclaimer\n\nThis tool is still in development. It's not perfect by any means. It does what I need it to do, but it may not work for your use case. Please feel free to open an issue or a pull request if you find any bugs or have any suggestions. I only tested so many use cases, so I am sure there are many more that I have not thought of.\n\n## Installation\n\n```bash\npip install Pytest-File-Watcher\n```\n\n## Usage\n\nMain entrypoint\n\n```bash\npytest-w\n```\n\nYou can run the `--help` command to see all available options.\n\n```bash\npytest-w --help\n```\n\nor on any command.\n\n```bash\npytest-w test --help\n```\n\nYou can also view the `--version` of the tool.\n\n```bash\npytest-w --version\n```\n\n### Test Watching\n\nI strongly recommend using the `config.yaml` file to configure Pytest-File-Watcher. You can use the `configure` command to generate a `config.yaml` (see [#Config](#config)) file in the root of your project or if you prefer writing it yourself see [#Config (Advanced)](#config-advanced) section. As mentioned before this is quite opinionated. I personally do not like to pass many flags and commands when testing. Especially when those flags don't change, but it can be problematic to navigate a long line of shell command to edit something. Hence **use the config**.\n\\\nAnyway... The `test` command is the real reason you are here. It will watch your files and run your tests automatically when it detects changes. You need to pass the path to the folder you want to watch. You can just pass `./` to watch all files in the current directory.\n\n```bash\npytest-w test ./path/to/folder\n```\n\n### Test Flags\n\nThere are many flags supported by Pytest-File-Watcher. You can pass them when using the `test` command. These flags take priority over the `config.yaml` file if used.\n\\\nThe flags are quite self-explanatory. I will list them here for convenience.\n\\\nVerbose: `-v` or `--verbose`. Used when you want to see the full pytest output.\n\\\n**Note:** If you want a more verbose pytest output use the `-p` flag instead.\n\n```bash\npytest-w test ./path/to/folder -v\n```\n\nAuto Clear: `-a` or `--auto-clear`. Used when you want to clear the terminal after each test run.\n\n```bash\npytest-w test ./path/to/folder -c\n```\n\nConfig: `-c` or `--config`. Used when you want to pass a custom config file.\n\n```bash\npytest-w test ./path/to/folder -c \"path/to/config.yaml\"\n```\n\nIgnore: `-i` or `--ignore`. Used when you want to ignore certain folders.\n\n```bash\npytest-w test ./path/to/folder -i \"venv\" -i \"node_modules\"\n```\n\nExtensions: `-e` or `--extensions`. Used when you want to watch for extra file extensions.\n\n```bash\npytest-w test ./path/to/folder -e \".py\" -e \".txt\"\n```\n\nPassthrough: `-p` or `--passthrough`. Used when you want to pass extra flags to pytest.\n\n```bash\npytest-w test ./path/to/folder -t \"-k\" -t \"test_something\"\n```\n\nOn Pass: `--on-pass`. Used when you want to run a shell command when all tests pass.\n\n```bash\npytest-w test ./path/to/folder -p \"echo 'All tests passed'\"\n```\n\nOn Fail: `--on-fail`. Used when you want to run a shell command when a test fails.\n\n```bash\npytest-w test ./path/to/folder -f \"echo 'A test has failed'\"\n```\n\n### Config\n\nIf you are not familiar with yaml files, you can use this option to generate a `config.yaml` file in the root of your project.\n\n```bash\npytest-w configure create\n```\n\nYou can also edit the `config.yaml` file.\n\n```bash\npytest-w configure edit\n```\n\nAnd view the current configuration.\n\n```bash\npytest-w configure view\n```\n\nAll above commands accept the `--config` flag to specify a custom config file. The default is the current working path.\n\n```bash\npytest-w configure create --config \"path/to/config.yaml\"\n```\n\n### Config (Advanced)\n\nPytest-File-Watcher can be configured using a `config.yaml` file in the root of your project. Example of currently supported options:\n\n```yaml\nverbose: bool\nautoClear: bool\nonPass: shell-command\nonFail: shell-command\nextensions:\n  - string-item\nignore:\n  - string-item\npassthrough:\n  - string-item\n  - string-item\n```\n\nSee [example config](./example_config.yaml).\n\\\nThis will likely change in the future, and be expanded further. I will do my best to keep the documentation up-to-date.\n\n### Recommendation\n\nMy daily driver is WSL2 within Windows 10. I have found myself running Pytest-File-Watcher in the background while doing other operations in another terminal tab and often forgetting to check the status of tests. I know that on linux you can use [notify-send](https://vaskovsky.net/notify-send/linux.html) to send notifications to your desktop. Well, on WSL you can use [wsl-notify-send](https://github.com/stuartleeks/wsl-notify-send) which essentially sends a notification to the Windows notification center. I have found this to be very useful and I highly recommend checking it out and using it in your own projects.\n\\\nI have added the following to my `config.yaml` file:\n\n```yaml\nonPass: wsl-notify-send.exe --category \"Pytest-File-Watcher\" \"All tests passed\"\nonFail: wsl-notify-send.exe --category \"Pytest-File-Watcher\" \"A test has failed\"\n```\n\nNow I can forget about Pytest-File-Watcher and it will notify me when it is done running tests. Not sure how this will work on other platforms, but I am sure there is a similar tool for MacOS.\n\n## Manual Build\n\nIf you want to build the project manually, you can do so by cloning the repository. I recommend using a virtual environment.\n\n```bash\npython -m venv venv\nsource venv/bin/activate\n```\n\nThen install the dependencies.\n\n```bash\npip install -r requirements.txt\n```\n\nAnd finally build the project.\n\n```bash\npip install -e .\n```\n\nThen you can run the tool whenever you are in that virtual environment.\n\n## Contributing\n\nContributions are welcome! Please feel free to open an issue or a pull request.\n\n## Acknowledgements\n\n- [pytest-watch](https://github.com/joeyespo/pytest-watch)\n- [watchfiles](https://github.com/samuelcolvin/watchfiles)\n- [typer](https://github.com/tiangolo/typer)\n\n## Author\n\n[Deviljin112](https://github.com/Deviljin112)\n\n## License\n\nMIT\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Pytest-File-Watcher is a CLI tool that watches for changes in your code and runs pytest on the changed files.",
    "version": "0.2.4",
    "split_keywords": [
        "python",
        "pytest",
        "testing",
        "testing-tools",
        "watch",
        "watcher"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "71d33caf1201b5c337626d6ebf440982caf7f647b5440e0330ba103839927da8",
                "md5": "61b9663493f6f321c2ee7a76e55748cf",
                "sha256": "8002816d6178299cd446548948d0903367ba65c5ce9ced9a8d4bf8fcd200d048"
            },
            "downloads": -1,
            "filename": "pytest_file_watcher-0.2.4-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "61b9663493f6f321c2ee7a76e55748cf",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9",
            "size": 8739,
            "upload_time": "2023-03-23T22:29:22",
            "upload_time_iso_8601": "2023-03-23T22:29:22.394036Z",
            "url": "https://files.pythonhosted.org/packages/71/d3/3caf1201b5c337626d6ebf440982caf7f647b5440e0330ba103839927da8/pytest_file_watcher-0.2.4-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "cdd59bc4438e6eb681aee3b098b81f1d10a81d449e23fb662398b5ec97c163d6",
                "md5": "17a32159c47954571505974e2d25be94",
                "sha256": "b3d311bbadd030d80e91657531b04431570c0bd1bd9e9ed1c5540e23090f29b4"
            },
            "downloads": -1,
            "filename": "pytest-file-watcher-0.2.4.tar.gz",
            "has_sig": false,
            "md5_digest": "17a32159c47954571505974e2d25be94",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9",
            "size": 7580,
            "upload_time": "2023-03-23T22:29:23",
            "upload_time_iso_8601": "2023-03-23T22:29:23.561377Z",
            "url": "https://files.pythonhosted.org/packages/cd/d5/9bc4438e6eb681aee3b098b81f1d10a81d449e23fb662398b5ec97c163d6/pytest-file-watcher-0.2.4.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-03-23 22:29:23",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "deviljin112",
    "github_project": "Pytest-File-Watcher",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [],
    "lcname": "pytest-file-watcher"
}
        
Elapsed time: 0.05734s