Commit Graph

1715 Commits

Author SHA1 Message Date
Ran Benita 7484e346f9
Merge pull request #6711 from bluetech/mv-exitcode
Move ExitCode's definition from _pytest.main to _pytest.config
2020-02-11 09:49:38 +02:00
Ran Benita d33da078a8 Move ExitCode's definition from _pytest.main to _pytest.config
ExitCode is used in several internal modules and hooks and so with type
annotations added, needs to be imported a lot.

_pytest.main, being the entry point, generally sits at the top of the
import tree.

So, it's not great to have ExitCode defined in _pytest.main, because it
will cause a lot of import cycles once type annotations are added (in
fact there is already one, which this change removes).

Move it to _pytest.config instead.

_pytest.main still imports ExitCode, so importing from there still
works, although external users should really be importing from `pytest`.
2020-02-10 23:55:06 +02:00
Stefan Scherfke d59adc61f9 Reverse / fix meaning of "+/-" in error diffs
The convention is "assert result is expected".  Pytest's error diffs now
reflect this. "-" means that sth. expected is missing in the result and
"+" means that there are unexpected extras in the result.

Fixes: #3333
2020-02-10 21:12:37 +01:00
Ran Benita 7cc513b2af Remove unused NodeMarkers
This class was both added and became unused during the development of a
PR:
https://github.com/pytest-dev/pytest/pull/3317
2020-02-10 22:05:25 +02:00
Ran Benita 1ebca37689
Merge pull request #6708 from bluetech/redundant-commas-2
Remove some redundant commas
2020-02-10 21:26:55 +02:00
Ran Benita 3e4e6297ce Remove unused field FixtureManager._arg2finish
Not used since 4f0879ff9b.
2020-02-10 17:30:20 +02:00
Ran Benita 0b2b40e35d Remove some redundant commas
Fix mypy errors:

src/_pytest/runner.py:36: error: "addoption" of "OptionGroup" does not return a value  [func-returns-value]
src/_pytest/helpconfig.py:64: error: "addoption" of "OptionGroup" does not return a value  [func-returns-value]
src/_pytest/terminal.py:67: error: "_addoption" of "OptionGroup" does not return a value  [func-returns-value]
src/_pytest/terminal.py:75: error: "_addoption" of "OptionGroup" does not return a value  [func-returns-value]
2020-02-10 17:28:05 +02:00
Daniel Hahler f9dd58000a
Fix CaptureManager.__repr__ (#6697) 2020-02-10 13:03:05 +01:00
Daniel Hahler 30cb598e9c
Typing around/from types in docs (#6699) 2020-02-09 11:42:07 +01:00
Daniel Hahler 114de91ab7 factor out _determine_main_color
(cherry picked from commit f36b9f7fa4fa1af7130406166df5c2be668e50c9)
2020-02-09 00:26:38 +01:00
Daniel Hahler 7a7c634e33 factor out KNOWN_TYPES
(cherry picked from commit 1180aedee727f7e8468fdc5561a87e12865622c6)
2020-02-09 00:26:26 +01:00
Daniel Hahler b4ace46c42
capture: cleanup item fixture handling (#6663)
This started by looking at how to get the current test item in general,
and then I noticed that it is not necessary for the capture plugin to
track it manually in the first place.
2020-02-07 19:23:37 +01:00
Daniel Hahler a8fc056aad
Handle `Exit` exception in `pytest_sessionfinish` (#6660) 2020-02-07 00:40:10 +01:00
Vladyslav Rachek 9e262038c8
[parametrize] enforce explicit argnames declaration (#6330)
Every argname used in `parametrize` either must
be declared explicitly in the python test function, or via
`indirect` list

Fix #5712
2020-02-06 20:20:25 -03:00
Minuddin Ahmed Rana ef437ea448
Remove incorrect choices comment (#6677) 2020-02-05 20:45:21 +01:00
Daniel Hahler cdc7e13067
pytester: clarify _makefile signature (#6675) 2020-02-05 20:42:57 +01:00
Daniel Hahler 39d9f7cff5
pytester: LineMatcher: typing, docs, consecutive line matching (#6653) 2020-02-04 22:47:18 +01:00
Daniel Hahler 632800add5
internal: clean up getfslineno (#6656) 2020-02-04 22:46:00 +01:00
Daniel Hahler 5a4c1b628b
Use inspect.getdoc to massage fixture docstrings (#6668)
Ref: https://github.com/pytest-dev/pytest/pull/2575
2020-02-04 03:07:53 +01:00
Daniel Hahler aa0328782f
assertion: save/restore hooks on item (#6646) 2020-02-04 02:56:23 +01:00
Daniel Hahler 9c7f1d9b32 Remove compat.getfslineno 2020-02-04 02:40:59 +01:00
Daniel Hahler dab90ef726 typing: fix getfslineno
Closes https://github.com/pytest-dev/pytest/pull/6590.
2020-02-03 19:09:08 +01:00
Daniel Hahler 61f2a26675 Code/getfslineno: keep empty co_filename
Previously this would be turned via `py.path.local("")` into the current
working directory.

This appears to be what `fspath = fn and py.path.local(fn) or None`
tries to avoid in `getfslineno`'s `TypeError` handling already, if
`Code` would raise it.
2020-02-03 19:09:08 +01:00
Daniel Hahler b0d45267c5 internal: clean up getfslineno
Everything was using `_pytest.compat.getfslineno` basically, which
wrapped `_pytest._code.source.getfslineno`.

This moves the extra code from there into it directly, and uses the
latter everywhere.

This helps to eventually remove the one in compat eventually, and also
causes less cyclic imports.
2020-02-03 19:09:08 +01:00
Daniel Hahler 75714ee707
pluginmanager.consider_preparse: add exclude_only kwarg (#6443)
Plugins specified with ``-p`` are now loaded after internal plugins, which
results in their hooks being called *before* the internal ones.

This makes the ``-p`` behavior consistent with ``PYTEST_PLUGINS``.

* fix/adjust test_disable_plugin_autoload
* adjust test_plugin_loading_order
2020-02-03 14:10:54 +01:00
Daniel Hahler 8ec4d03c91
Inline FunctionMixin with Function (#6664)
`Generator` was removed in 7eb28f9eb, and this pleases mypy to correctly
complain that `FunctionMixin` has no `config` (within
`_prunetraceback`).

* typing: _prunetraceback

* minor: imports, typing
2020-02-03 10:25:32 +01:00
Daniel Hahler 99d162e44a Handle `Exit` exception in `pytest_sessionfinish`
Similar to a7268aa (https://github.com/pytest-dev/pytest/pull/6258).
2020-02-02 23:13:23 +01:00
Ran Benita 8bd612b367 typing: wrap_session
Pulled out of https://github.com/pytest-dev/pytest/pull/6556.
2020-02-02 23:12:48 +01:00
Daniel Hahler 5256542ea4 pytester.LineMatcher: add support for matching lines consecutively 2020-02-01 23:48:58 +01:00
Daniel Hahler 50f81db817 revisit/improve docstrings 2020-02-01 23:48:58 +01:00
Daniel Hahler 2681b0aed7 typing: pytester: LineMatcher 2020-02-01 23:48:57 +01:00
Daniel Hahler b10ab0211c Use TypeError instead of AssertionError for no sequence
Improve/extends tests.
2020-02-01 23:48:57 +01:00
Daniel Hahler a9c5d31806
PyCollector._genfunctions: use already created fixtureinfo (#6636)
`Function` creates a `_fixtureinfo` already:
https://github.com/pytest-dev/pytest/blob/fed535694/src/_pytest/python.py#L1392-L1395
2020-02-01 06:27:41 +01:00
Bruno Oliveira 39b25ddcf3
Remove deprecated 'pytest_itemstart' hook (#6637)
Remove deprecated 'pytest_itemstart' hook
2020-01-31 16:12:27 -03:00
Ran Benita a435faad5c Merge branch 'master' into master-to-features 2020-01-31 11:27:06 +02:00
Bruno Oliveira 70739296e1 Remove deprecated 'pytest_itemstart' hook
This hook has been deprecated/removed for more than 10 years
in a2fe6714f8.
2020-01-30 21:03:29 -03:00
Daniel Hahler 1dc265e34a
Merge pull request #6633 from blueyed/async_warn
python: factor out async_warn
2020-01-30 23:39:06 +01:00
Daniel Hahler e7a833635d
Merge pull request #6635 from blueyed/fix-todo
minor: doc: getfuncargnames: move TODO out of docstring
2020-01-30 23:37:41 +01:00
Daniel Hahler fed5356941
Merge pull request #6634 from blueyed/fixtures-move-import
fixtures: move import of ParameterSet to top level
2020-01-30 23:22:39 +01:00
Daniel Hahler 5b81bd862c minor: doc: getfuncargnames: move TODO out of docstring 2020-01-30 23:22:10 +01:00
Daniel Hahler 2902c7263c fixtures: move import of ParameterSet to top level
This gets typically used always (via `getfixtureinfo`).
2020-01-30 23:03:02 +01:00
Daniel Hahler 442dccef65 python: factor out async_warn 2020-01-30 22:55:23 +01:00
Daniel Hahler 88b800355a typing: pytest_collection 2020-01-30 19:58:43 +01:00
Daniel Hahler 28b8f3ca3a
Merge pull request #6461 from blueyed/test-package-upstream
Package: typing, cleanup
2020-01-30 16:41:47 +01:00
Bruno Oliveira 64ab68ff0a
Fix 6341 disallow session config in fromparent (#6387)
Fix 6341 disallow session config in fromparent
2020-01-29 19:21:02 -03:00
Anthony Sottile 595d62bc3e
Merge pull request #6607 from asottile/empty_string_parametrize_nodeid
Fix node ids which contain a parametrized empty-string variable
2020-01-29 08:42:04 -08:00
Daniel Hahler 55e5817570 Merge master into features 2020-01-29 03:07:35 +01:00
Daniel Hahler 3ccf2a5e61
Merge pull request #6524 from blueyed/reportchars-default
terminal: default to `fE` with `-r` (reportchars)
2020-01-29 01:00:41 +01:00
Bruno Oliveira d282424589
Fix unguarded `==` comparison in fixtures. (#6541)
Fix unguarded `==` comparison in fixtures.
2020-01-28 20:54:14 -03:00
Daniel Hahler ddaa5d88ac terminal: default to `fE` with `-r` (reportchars)
Adds handling of `N` to reset `reportchars`, which can be used to get
the old behavior (`-rN`), and also allows for an alternative to
`--disable-warnings` (https://github.com/pytest-dev/pytest/issues/5066),
since `w` was included by default (without `--disable-warnings`).

Fixes https://github.com/pytest-dev/pytest/issues/6454
2020-01-29 00:33:15 +01:00
Daniel Hahler 4ff90b1fcf
Merge pull request #6606 from blueyed/typing-monkeypatch-context
typing: MonkeyPatch.context
2020-01-29 00:12:53 +01:00
Anthony Sottile abd5fc80e8 Fix node ids which contain a parametrized empty-string variable 2020-01-28 13:27:54 -08:00
Holger Kohr 80d4dd6f0b Replace `==` with `is` for comparison of cache keys
Closes #6497
2020-01-28 18:05:53 -03:00
Ran Benita e440b43258
Merge pull request #6555 from bluetech/nodes-cache-split
Split Session._collection_node_cache to 3 mutually exclusive parts
2020-01-28 22:49:42 +02:00
Daniel Hahler e25d46aae6 typing: MonkeyPatch.context 2020-01-28 21:44:30 +01:00
Daniel Hahler 7c87874277 source_path: py.path.local directly
Via bc7282576.
2020-01-28 19:02:41 +01:00
Daniel Hahler 1cf9e68dbc tests: cover absolute path handling in _compute_fixture_value 2020-01-28 18:53:28 +01:00
Daniel Hahler 18ac7e0b79
Merge pull request #6593 from blueyed/typing-ignore-more-itertools
typing: ignore false positive with more-itertools
2020-01-28 14:24:24 +01:00
Daniel Hahler 12c5a6af64 typing: fix Code.path
Fixes:

> src/_pytest/_code/code.py:83: error: Incompatible types in assignment
>   (expression has type "str", variable has type "local")  [assignment]
2020-01-28 01:49:45 +01:00
Daniel Hahler 30922ee694 Merge master into features 2020-01-28 01:40:14 +01:00
Daniel Hahler 35ba053f00 typing: ignore false positive with more-itertools
Fixed in https://github.com/erikrose/more-itertools/pull/374.
2020-01-28 01:23:44 +01:00
Daniel Hahler 9c716e4d74 typing: Testdir.plugins 2020-01-28 00:41:46 +01:00
Daniel Hahler 94ac0f7e6b typing: self._mod_collections, collect_by_name 2020-01-28 00:41:46 +01:00
Daniel Hahler 440881d63a typing: Testdir.__init__ 2020-01-28 00:41:46 +01:00
Ran Benita ae5d16be10 typing: FSHookProxy/gethookproxy
Taken out of https://github.com/pytest-dev/pytest/pull/6556.
2020-01-27 20:57:44 +01:00
Daniel Hahler bf5c76359c fixup! typing: tests: tmpfile 2020-01-26 23:14:32 +01:00
Daniel Hahler 3f8f395210 typing: EncodedFile 2020-01-25 19:20:48 +01:00
Daniel Hahler e2934c3f8c Move common code between Session and Package to FSCollector 2020-01-25 19:04:01 +01:00
Daniel Hahler 6b7e1a246c Sync `{Session,Package}.gethookproxy`
Only copy'n'paste error from c416b1d935.
2020-01-25 19:04:01 +01:00
Daniel Hahler 817c094ce6 Clean up Package.__init__
Makes `parent` a required arg, which would have failed before via
`parent.session` anyway.

Keeps calling/passing unused args for B/C.
2020-01-25 19:04:01 +01:00
Daniel Hahler 039d582b52 Fix `EncodedFile.writelines`
This is implemented by the underlying stream already, which additionally
checks if the stream is not closed, and calls `write` per line.

Ref/via: https://github.com/pytest-dev/pytest/pull/6558#issuecomment-578210807
2020-01-25 18:06:50 +01:00
Daniel Hahler 9b8039cf09 Sync `{Session,Package}._recurse` 2020-01-25 16:44:20 +01:00
Daniel Hahler 57512aa997 _get_main_color: no yellow ("boring") for non-last item
- refactor _get_main_color/build_summary_stats_line
- factor out property _is_last_item; test_summary_stats: tr._is_last_item
- _write_progress_information_filling_space: remove color arg
- use setter for stats, handling main color
- _get_main_color: skip cache for last item
- Handle random order in test for py35.
2020-01-25 15:09:02 +01:00
Daniel Hahler c51173d426 Merge master into features 2020-01-25 14:18:02 +01:00
Ran Benita 94d8c071b6 Remove a couple of redundant commas
Mypy complains about this once the function is typed:

src/_pytest/main.py:85: error: "_addoption" of "OptionGroup" does not return a value
src/_pytest/main.py:133: error: "addoption" of "OptionGroup" does not return a value
2020-01-25 14:12:47 +01:00
Ran Benita f3967333a1 Split Session._collection_node_cache to 3 mutually exclusive parts
Previously, this cache was used with 3 different and mutually exclusive
key-type -> value-type combinations. Mypy can't properly type this. It's
also quite confusing.

Split to 3 different dicts instead.
2020-01-25 14:31:12 +02:00
Ran Benita a76bc64c54
Merge pull request #6547 from bluetech/session-initialparts
Refactor Session._initialparts to have a more explicit type
2020-01-25 14:30:26 +02:00
Ran Benita dd5c2b22bd Refactor Session._initialparts to have a more explicit type
Previously, _initialparts was a list whose first item was a
`py.path.local` and the rest were `str`s. This is not something that
mypy is capable of modeling. The type `List[Union[str, py.path.local]]`
is too broad and would require asserts for every access.

Instead, make each item a `Tuple[py.path.local, List[str]]`. This way
the structure is clear and the types are accurate.

To make sure any users who might have been accessing this (private)
field will not break silently, change the name to _initial_parts.
2020-01-25 13:57:49 +02:00
Tomáš Gavenčiak 5e15c86cc6 Fix EncodedFile.write return value
Make EncodedFile, used for captured output streams, method .write return
the number of characters written. Add test for captured stderr write.
Fixes #6557.

Co-Authored-By: Bruno Oliveira <nicoddemus@gmail.com>
2020-01-25 10:36:23 +01:00
Daniel Hahler 09bdbffbde Merge master into features
Conflicts:
	src/_pytest/_code/code.py
	src/_pytest/main.py
2020-01-24 23:44:50 +01:00
Daniel Hahler 03bc8aba4e config: typing for create_terminal_writer, re-export TerminalWriter
This also imports `TerminalWriter` explicitly via `_pytest._io`,
allowing for easier extending / replacing it.
2020-01-23 14:09:37 +01:00
Daniel Hahler 6b13379f37
Merge pull request #6521 from blueyed/harden-nose-raises
tests: improve test for `nose.raises`
2020-01-23 13:42:14 +01:00
Ran Benita 9dcdea5de7 Rewrite Item.location to be clearer with regard to types 2020-01-23 13:25:15 +01:00
Daniel Hahler 8521503246
Merge pull request #6527 from blueyed/typing-getfslineno
typing: fix/adjust _code.source.getfslineno
2020-01-23 13:17:47 +01:00
Ran Benita 0b6258ab5b PyCollector.collect: use explicit cast to `str`
Ref: https://github.com/pytest-dev/pytest/pull/6521#pullrequestreview-347234792
2020-01-23 12:54:52 +01:00
Daniel Hahler 9c7b3c57d7 typing: PyobjMixin.reportinfo, getfslineno 2020-01-23 10:45:31 +01:00
Daniel Hahler 1350c601dc Node.location: handle str with _node_location_to_relpath 2020-01-23 10:45:31 +01:00
Daniel Hahler ef112fd7dd Revert "Revert "Fix type errors after adding types to the `py` dependency""
Without changes to test_itemreport_reportinfo.

This reverts commit fb99b5c66e.

Conflicts:
	testing/test_nose.py
2020-01-23 10:45:27 +01:00
Daniel Hahler ad02f6f879
Merge pull request #6525 from blueyed/typing-session
typing: Session.__init__
2020-01-23 00:16:08 +01:00
Daniel Hahler bd6ba3f3e1 typing: Session.__init__
Pulled out of https://github.com/pytest-dev/pytest/pull/6491.
2020-01-23 00:07:59 +01:00
Bruno Oliveira e17f5fad14
Clear node collection cache after collection is done (#6491)
Clear node collection cache after collection is done
2020-01-22 16:08:59 -03:00
Daniel Hahler aca1723d45 Merge master into features 2020-01-22 19:18:13 +01:00
Bruno Oliveira 93b74d28d2 Merge remote-tracking branch 'upstream/master' into mm
Conflicts:
 * 	src/_pytest/_code/code.py
 * 	src/_pytest/main.py
 * 	testing/python/metafunc.py
 * 	testing/test_parseopt.py
 * 	testing/test_pytester.py
2020-01-22 11:03:45 -03:00
Daniel Hahler b8787b8732 tests: fix test_cwd_snapshot
Without restoring the cwd, successive tests might fail to parse the
config (via `_pytest.config._prepareconfig()`, for when `--lsof` is
used).

And it is good practice to restore the cwd in any case anyway.
2020-01-22 14:34:11 +01:00
Daniel Hahler 62db3f7abc typing: fix/adjust _code.source.getfslineno 2020-01-21 19:48:17 +01:00
Daniel Hahler 7ee27fedee doc: fix Code.path: might return str 2020-01-21 19:46:43 +01:00
Bruno Oliveira 7b1e3d1c9a Clear collection caches after collection is done
Also rename the involved variables to convey its intent better and
add type hints
2020-01-21 07:29:13 -03:00
Ran Benita fb99b5c66e Revert "Fix type errors after adding types to the `py` dependency"
This reverts commit 930a158a6a.

Regression test from Bruno Oliveira.
2020-01-20 23:44:56 +02:00
Bruno Oliveira cdaa9c06e1
Revert "fixtures register finalizers with all fixtures before t… (#6496)
Revert "fixtures register finalizers with all fixtures before them in the stack"
2020-01-20 13:49:00 -03:00
Ran Benita 3392be37e1 Fix check_untyped_defs in test_runner 2020-01-19 20:01:07 +02:00