Pass any verbosity from test/run_test.py to pytest (#48204)

Summary:
Previously it was only possible to pass up to one [verbosity level](https://adamj.eu/tech/2019/10/03/my-most-used-pytest-commandline-flags/) to `pytest` when running a test via `test/run_test.py`. Presumably that behavior was never added because `unittest` [doesn't do anything extra](https://stackoverflow.com/a/1322648/5044950) when given more than one `--verbose` flag. This PR removes that limitation.

Pull Request resolved: https://github.com/pytorch/pytorch/pull/48204

Test Plan:
Make a dummy `pytest`-style file `test/test_foo.py`:
```py
def test_bar():
    assert 'hello\n' * 10 == 'hello\n' * 20
```
Then add `'test_foo'` to both `TESTS` and `USE_PYTEST_LIST` in `test/run_test.py`, and run this command:
```sh
test/run_test.py -vvi test_foo
```

Reviewed By: walterddr

Differential Revision: D25069147

Pulled By: samestep

fbshipit-source-id: 2765ee78d18cc84ea0e262520838993f9e9ee04f
This commit is contained in:
Sam Estep 2020-11-19 07:57:09 -08:00 committed by Facebook GitHub Bot
parent 370310bedb
commit c4a6df989c

View File

@ -309,7 +309,7 @@ def get_executable_command(options, allow_pytest):
def run_test(test_module, test_directory, options, launcher_cmd=None, extra_unittest_args=None):
unittest_args = options.additional_unittest_args.copy()
if options.verbose:
unittest_args.append('--verbose')
unittest_args.append(f'-{"v"*options.verbose}') # in case of pytest
if test_module in RUN_PARALLEL_BLOCKLIST:
unittest_args = [arg for arg in unittest_args if not arg.startswith('--run-parallel')]
if extra_unittest_args:
@ -477,7 +477,8 @@ def parse_args():
parser.add_argument(
'-v',
'--verbose',
action='store_true',
action='count',
default=0,
help='print verbose information and test-by-test results')
parser.add_argument(
'--jit',