Repository: tox-dev/tox
Pull request #1733 (2020-11-06 04:16:05)

tests: add full coverage for tox.session.cmd.run.common
**FOR THE REWRITE BRANCH**

Add full test coverage for `session/cmd/run/common.py`

## Contribution checklist:

(also see [CONTRIBUTING.rst](../tree/master/CONTRIBUTING.rst) for details)

- [x] wrote descriptive pull request text
- [x] added/updated test(s)
- [x] updated/extended the documentation - N/A
- [x] added relevant [issue keyword](https://help.github.com/articles/closing-issues-using-keywords/)
      in message body - N/A
- [x] added news fragment in [changelog folder](../tree/master/docs/changelog) - N/A
  * fragment name: `<issue number>.<type>.rst` for example (588.bugfix.rst)
  * `<type>` is must be one of `bugfix`, `feature`, `deprecation`,`breaking`, `doc`, `misc`
  * if PR has no issue: consider creating one first or change it to the PR number after creating the PR
  * "sign" fragment with "by :user:`<your username>`"
  * please use full sentences with correct case and punctuation, for example: "Fix issue with non-ascii contents in doctest text files - by :user:`superuser`."
  * also see [examples](../tree/master/docs/changelog)
- [x] added yourself to `CONTRIBUTORS` (preserving alphabetical order) -N/A


codecov[bot]: # [Codecov](https://codecov.io/gh/tox-dev/tox/pull/1733?src=pr&el=h1) Report
> Merging [#1733](https://codecov.io/gh/tox-dev/tox/pull/1733?src=pr&el=desc) into [rewrite](https://codecov.io/gh/tox-dev/tox/commit/2c8d922aa37c02d128142e31e5f2e5c9452b3096?el=desc) will **increase** coverage by `0.16%`.
> The diff coverage is `100.00%`.

[![Impacted file tree graph](https://codecov.io/gh/tox-dev/tox/pull/1733/graphs/tree.svg?width=650&height=150&src=pr&token=DYodAwDCZ5)](https://codecov.io/gh/tox-dev/tox/pull/1733?src=pr&el=tree)

```diff
@@             Coverage Diff             @@
##           rewrite    #1733      +/-   ##
===========================================
+ Coverage    92.09%   92.25%   +0.16%     
===========================================
  Files          118      117       -1     
  Lines         4629     4547      -82     
  Branches       495      475      -20     
===========================================
- Hits          4263     4195      -68     
+ Misses         305      299       -6     
+ Partials        61       53       -8     
```

| Flag | Coverage Δ | |
|---|---|---|
| tests | `92.25% <100.00%> (+0.16%)` | :arrow_up: |

Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags#carryforward-flags-in-the-pull-request-comment) to find out more.

| [Impacted Files](https://codecov.io/gh/tox-dev/tox/pull/1733?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [src/tox/session/cmd/run/common.py](https://codecov.io/gh/tox-dev/tox/pull/1733/diff?src=pr&el=tree#diff-c3JjL3RveC9zZXNzaW9uL2NtZC9ydW4vY29tbW9uLnB5) | `100.00% <100.00%> (+21.05%)` | :arrow_up: |
| [tests/session/cmd/run/test\_common.py](https://codecov.io/gh/tox-dev/tox/pull/1733/diff?src=pr&el=tree#diff-dGVzdHMvc2Vzc2lvbi9jbWQvcnVuL3Rlc3RfY29tbW9uLnB5) | `100.00% <100.00%> (ø)` | |
| [src/tox/tox\_env/api.py](https://codecov.io/gh/tox-dev/tox/pull/1733/diff?src=pr&el=tree#diff-c3JjL3RveC90b3hfZW52L2FwaS5weQ==) | `89.18% <0.00%> (-1.97%)` | :arrow_down: |
| [src/tox/execute/request.py](https://codecov.io/gh/tox-dev/tox/pull/1733/diff?src=pr&el=tree#diff-c3JjL3RveC9leGVjdXRlL3JlcXVlc3QucHk=) | `100.00% <0.00%> (ø)` | |
| [tests/session/cmd/test\_show\_config.py](https://codecov.io/gh/tox-dev/tox/pull/1733/diff?src=pr&el=tree#diff-dGVzdHMvc2Vzc2lvbi9jbWQvdGVzdF9zaG93X2NvbmZpZy5weQ==) | `100.00% <0.00%> (ø)` | |
| [tests/conftest.py](https://codecov.io/gh/tox-dev/tox/pull/1733/diff?src=pr&el=tree#diff-dGVzdHMvY29uZnRlc3QucHk=) | | |
| [...ecute/local\_sub\_process/read\_via\_thread\_windows.py](https://codecov.io/gh/tox-dev/tox/pull/1733/diff?src=pr&el=tree#diff-c3JjL3RveC9leGVjdXRlL2xvY2FsX3N1Yl9wcm9jZXNzL3JlYWRfdmlhX3RocmVhZF93aW5kb3dzLnB5) | | |
| [src/tox/tox\_env/python/api.py](https://codecov.io/gh/tox-dev/tox/pull/1733/diff?src=pr&el=tree#diff-c3JjL3RveC90b3hfZW52L3B5dGhvbi9hcGkucHk=) | `91.00% <0.00%> (+0.80%)` | :arrow_up: |
| [src/tox/util/spinner.py](https://codecov.io/gh/tox-dev/tox/pull/1733/diff?src=pr&el=tree#diff-c3JjL3RveC91dGlsL3NwaW5uZXIucHk=) | `100.00% <0.00%> (+2.41%)` | :arrow_up: |
| ... and [2 more](https://codecov.io/gh/tox-dev/tox/pull/1733/diff?src=pr&el=tree-more) | |

------

[Continue to review full report at Codecov](https://codecov.io/gh/tox-dev/tox/pull/1733?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/tox-dev/tox/pull/1733?src=pr&el=footer). Last update [2c8d922...bce190f](https://codecov.io/gh/tox-dev/tox/pull/1733?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

gnikonorov: This PR suffers from the same unrelated timeouts as in my previous testing PRs  ( `tests/session/cmd/run/test_int_setuptools.py::test_setuptools_package_py_project` ), @gaborbernat 

Patch:
diff --git a/src/tox/session/cmd/run/common.py b/src/tox/session/cmd/run/common.py
index 176bbd19..66526575 100644
--- a/src/tox/session/cmd/run/common.py
+++ b/src/tox/session/cmd/run/common.py
@@ -14,7 +14,7 @@ class SkipMissingInterpreterAction(Action):
     ) -> None:
         value = "true" if values is None else values
         if value not in ("config", "true", "false"):
-            raise ArgumentTypeError("value must be config, true or false")
+            raise ArgumentTypeError(f"value must be 'config', 'true', or 'false' (got {repr(value)})")
         setattr(args, self.dest, value)
 
 


Test patch:
diff --git a/tests/session/cmd/run/test_common.py b/tests/session/cmd/run/test_common.py
new file mode 100644
index 00000000..37f2a386
--- /dev/null
+++ b/tests/session/cmd/run/test_common.py
@@ -0,0 +1,20 @@
+from argparse import ArgumentParser, ArgumentTypeError, Namespace
+from typing import Optional
+
+import pytest
+
+from tox.session.cmd.run.common import SkipMissingInterpreterAction
+
+
+@pytest.mark.parametrize("values", ["config", None, "true", "false"])
+def test_skip_missing_interpreter_action_ok(values: Optional[str]) -> None:
+    args_namespace = Namespace()
+    SkipMissingInterpreterAction(option_strings=["-i"], dest="into")(ArgumentParser(), args_namespace, values)
+    expected = "true" if values is None else values
+    assert args_namespace.into == expected
+
+
+def test_skip_missing_interpreter_action_nok() -> None:
+    argument_parser = ArgumentParser()
+    with pytest.raises(ArgumentTypeError, match=r"value must be 'config', 'true', or 'false' \(got 'bad value'\)"):
+        SkipMissingInterpreterAction(option_strings=["-i"], dest="into")(argument_parser, Namespace(), "bad value")