Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f000d81

Browse files
HexDecimalkvas-it
authored andcommitted
Refactor main fixture to act more like subprocess.
Support sequence command arguments, deprecated old argument parameter. Added check keyword support, this acts almost exactly like subprocess including raising CalledProcessError. Added shell keyword, it should work for most simple cases. Also adds support for PathLike values in commands. New features are covered by tests. Refactors methods in the ScriptRunner class. Many functions are now staticmethod and classmethod, it's possible that these methods do not need to be in the class itself. Refactored and added several context managers. run_inprocess now uses ExitStack to collect it's managers. stdout and stderr now use contextlib for redirects. Supported keywords were made into parameters. Unknown keywords in options will raise a warning.
1 parent 8a0d4ec commit f000d81

File tree

3 files changed

+288
-102
lines changed

3 files changed

+288
-102
lines changed

README.md

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,12 @@ We could use pytest-console-scripts to test the `foobar` script:
5757

5858
```py
5959
def test_foo_bar(script_runner):
60-
ret = script_runner.run('foobar', '--version')
61-
assert ret.success
62-
assert ret.stdout == '3.2.1\n'
63-
assert ret.stderr == ''
60+
result = script_runner.run(['foobar', '--version'])
61+
assert result.returncode == 0
62+
assert result.stdout == '3.2.1\n'
63+
assert result.stderr == ''
64+
65+
script_runner.run('foobar --version', shell=True, check=True)
6466
```
6567

6668
This would use the `script_runner` fixture provided by the plugin to
@@ -75,6 +77,9 @@ following keyword arguments can be used:
7577
environment.
7678
- `stdin` - a file-like object that will be piped to standard input of the
7779
script.
80+
- `check` - raises an exception if `returncode != 0`, defaults to False.
81+
- `shell` - mimic shell execution, this should work well for simple cases,
82+
defaults to False.
7883

7984
Type-hinting is also supported.
8085
You may type-hint the fixture with the following code:

0 commit comments

Comments
 (0)