Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ Configuration
-------------

CLI options can be added to a `[pytest-watch]` section in your
[pytest.ini file][pytest.ini] to persist them in your project. For example:
*pytest.ini* or *setup.cfg* file to persist them in your project. For example:

```ini
# pytest.ini
Expand All @@ -153,6 +153,23 @@ ignore = ./integration-tests
nobeep = True
```

The `[pytest-watch]` section may additionally provide the `testpaths` and/or
the `watchpaths` options. These options are only considered when no directories
were provided in the command. When both `testpaths` and `watchpaths` are
provided then the former are provided to pytest while the latter are watched.
When only the `testpaths` are provided then these are both watched and passed
to pytest. When only the `watchpaths` are provided then these paths are
watched but not passed to pytest, allowing it to pick up the `testpaths`
provided in the `[pytest]` section. For example:

```ini
[pytest]
addopts = --maxfail=2
testpaths = ./tests

[pytest-watch]
watchpaths = ./lib ./tests
```

Alternatives
------------
Expand Down
2 changes: 1 addition & 1 deletion pytest_watch/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
:license: MIT, see LICENSE for more details.
"""

__version__ = '4.2.0'
__version__ = '2021.01.29'


from .command import main, doc, version
Expand Down
14 changes: 9 additions & 5 deletions pytest_watch/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,16 @@ def main(argv=None):
# Parse CLI arguments
args = docopt(doc, argv=argv, version=version)

# Get paths and initial pytest arguments
directories = args['<directory>']
pytest_args = list(directories)
# Get paths from the command
directories = args['<directory>'] or []
if '--' in directories:
index = directories.index('--')
pytest_args = directories[index + 1:]
directories = directories[:index]
del pytest_args[index]
else:
pytest_args = []
args['--testpaths'] = directories
args['--watchpaths'] = list(directories)

# Adjust pytest and --collect-only args
for ignore in args['--ignore'] or []:
Expand All @@ -82,6 +85,7 @@ def main(argv=None):
# Merge config file options
if not merge_config(args, pytest_args, verbose=args['--verbose']):
return 0
pytest_args = args['--testpaths'] + pytest_args

# Adjust pytest args
if args['--pdb']:
Expand All @@ -106,7 +110,7 @@ def main(argv=None):
return 2

# Run pytest and watch for changes
return watch(entries=directories,
return watch(entries=args['--watchpaths'] or args['--testpaths'],
ignore=args['--ignore'],
extensions=extensions,
beep_on_failure=not args['--nobeep'],
Expand Down
5 changes: 4 additions & 1 deletion pytest_watch/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,10 @@ def merge_config(args, pytest_args, silent=True, verbose=False):
continue

# Merge config option using the expected type
if isinstance(args[cli_name], list):
if cli_name == '--testpaths' or cli_name == '--watchpaths':
paths = config.get('pytest-watch', config_name).split()
args[cli_name].extend(paths)
elif isinstance(args[cli_name], list):
args[cli_name].append(config.get('pytest-watch', config_name))
elif isinstance(args[cli_name], bool):
args[cli_name] = config.getboolean('pytest-watch', config_name)
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def read(filename):

setup(
name='pytest-watch',
version='4.2.0',
version='2021.01.29',
description='Local continuous test runner with pytest and watchdog.',
long_description=read('README.rst'),
author='Joe Esposito',
Expand Down