From 59251c7460a6e0c9175d65296ca24f126557475a Mon Sep 17 00:00:00 2001 From: Wouter Van den Broeck Date: Sat, 18 Jan 2020 18:25:40 +0100 Subject: [PATCH 1/3] Add support for 'testpaths' and 'watchpaths' options in the ini file. --- README.md | 19 ++++++++++++++++++- pytest_watch/command.py | 14 +++++++++----- pytest_watch/config.py | 5 ++++- 3 files changed, 31 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 20b34cf..73d88a8 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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 ------------ diff --git a/pytest_watch/command.py b/pytest_watch/command.py index 4a8d84e..1738681 100644 --- a/pytest_watch/command.py +++ b/pytest_watch/command.py @@ -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[''] - pytest_args = list(directories) + # Get paths from the command + directories = args[''] 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 []: @@ -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']: @@ -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'], diff --git a/pytest_watch/config.py b/pytest_watch/config.py index cd11c46..7235826 100644 --- a/pytest_watch/config.py +++ b/pytest_watch/config.py @@ -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) From ec990c1af4ab19ac57d6941006586b49545e3871 Mon Sep 17 00:00:00 2001 From: Wouter Van den Broeck Date: Thu, 23 Apr 2020 14:34:06 +0200 Subject: [PATCH 2/3] chore: Prepare release. --- pytest_watch/__init__.py | 2 +- setup.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pytest_watch/__init__.py b/pytest_watch/__init__.py index aea03c4..a1427a5 100644 --- a/pytest_watch/__init__.py +++ b/pytest_watch/__init__.py @@ -8,7 +8,7 @@ :license: MIT, see LICENSE for more details. """ -__version__ = '4.2.0' +__version__ = '4.3.0-fork' from .command import main, doc, version diff --git a/setup.py b/setup.py index a5f2819..ee814c9 100644 --- a/setup.py +++ b/setup.py @@ -11,7 +11,7 @@ def read(filename): setup( name='pytest-watch', - version='4.2.0', + version='4.3.0-fork', description='Local continuous test runner with pytest and watchdog.', long_description=read('README.rst'), author='Joe Esposito', From f516fb04be2f54cfef23f7217826b0238f2cb63e Mon Sep 17 00:00:00 2001 From: Wouter Van den Broeck Date: Fri, 29 Jan 2021 18:56:55 +0100 Subject: [PATCH 3/3] fix: Update version to meet PEP-440 requirements. --- pytest_watch/__init__.py | 2 +- setup.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pytest_watch/__init__.py b/pytest_watch/__init__.py index a1427a5..ce07e9e 100644 --- a/pytest_watch/__init__.py +++ b/pytest_watch/__init__.py @@ -8,7 +8,7 @@ :license: MIT, see LICENSE for more details. """ -__version__ = '4.3.0-fork' +__version__ = '2021.01.29' from .command import main, doc, version diff --git a/setup.py b/setup.py index ee814c9..5099ffa 100644 --- a/setup.py +++ b/setup.py @@ -11,7 +11,7 @@ def read(filename): setup( name='pytest-watch', - version='4.3.0-fork', + version='2021.01.29', description='Local continuous test runner with pytest and watchdog.', long_description=read('README.rst'), author='Joe Esposito',