Commit Graph

3990 Commits

Author SHA1 Message Date
Bruno Oliveira 457d351941 Remove deprecated TerminalReporter.writer property 2020-08-19 08:13:34 -03:00
Bruno Oliveira 6ecbd008c4 Change junit_family default to xunit2 2020-08-19 08:13:06 -03:00
Bruno Oliveira 73e06373dc Hard failure when constructing Node subclasses 2020-08-19 08:13:03 -03:00
Bruno Oliveira c747dc5248 Drop support for positional arguments in @pytest.fixture 2020-08-19 08:11:42 -03:00
Bruno Oliveira 98530184a5 Remove funcargnames compatibility property 2020-08-19 08:11:39 -03:00
Ran Benita c98525bd21
Merge pull request #7648 from bluetech/pylint-abc2
Only define gethookproxy, isinitpath on Session
2020-08-18 15:45:11 +03:00
Bruno Oliveira afa4760cb8
Merge pull request #7643 from nicoddemus/issue-7628 2020-08-17 16:58:56 -03:00
Bruno Oliveira b426bb3443 Refactor Session._parsearg into a separate function for testing 2020-08-15 13:23:55 -03:00
Bruno Oliveira 2213016e40 Fix Module.name from full path without drive letter
Fix #7628
2020-08-15 09:39:14 -03:00
Ran Benita eddd993cf4 Only define gethookproxy, isinitpath on Session
This fixes an issue where pylint complains about missing implementations
of abstract methods in subclasses of `File` which only override
`collect()` (as they should).

It is also cleaner and makes sense, these methods really don't need to
be overridden.

The previous methods defined directly on `FSCollector` and `Package` are
deprecated, to be removed in pytest 7.

See commits e2934c3f8c and
f10ab021e2 for reference.
2020-08-15 13:40:16 +03:00
Bruno Oliveira 36c8bb492e get_dirs_from_args handles paths with invalid syntax
Fix #7638
2020-08-12 17:20:09 -03:00
Ran Benita acc9310c17 capture: add type annotations to CaptureFixture
It now has a str/bytes type parameter.
2020-08-10 18:14:47 +03:00
Ran Benita 8a66f0a96d capture: overcome a mypy limitation by making CaptureResult a regular class
See the code comment for the rationale.
2020-08-10 18:14:47 +03:00
Ran Benita f8c4e038fd Replace some usages of py.path.local 2020-08-06 18:46:17 +03:00
Ran Benita 70f3ad1c1f config/findpaths: convert from py.path.local to pathlib 2020-08-06 18:46:17 +03:00
Ran Benita e0d0951945 pathlib: add analogues to py.path.local's bestrelpath and common
An equivalent for these py.path.local functions is needed for some
upcoming py.path -> pathlib conversions.
2020-08-06 18:16:04 +03:00
Bruno Oliveira 67cb7ef673 Fix test_plain_unittest_does_not_support_async on pypy3
Fix #7624
2020-08-05 15:24:08 -03:00
Bruno Oliveira 44cd8a3a86
Demonstrate that plain unittest does not support async tests (#7607)
Co-authored-by: Ran Benita <ran@unusedvar.com>
2020-08-04 19:37:41 -03:00
Ran Benita fbf251f11d Improve typing of reports' longrepr field 2020-08-04 22:52:24 +03:00
Ran Benita 62ddf7a0e5 resultlog: add missing type annotations 2020-08-04 22:45:46 +03:00
Ran Benita 9ab14c6d9c typing: set warn_unreachable
This makes mypy raise an error whenever it detects code which is
statically unreachable, e.g.

    x: int
    if isinstance(x, str):
        ... # Statement is unreachable  [unreachable]

This is really neat and finds quite a few logic and typing bugs.

Sometimes the code is intentionally unreachable in terms of types, e.g.
raising TypeError when a function is given an argument with a wrong
type. In these cases a `type: ignore[unreachable]` is needed, but I
think it's a nice code hint.
2020-08-04 09:59:46 +03:00
Ran Benita b8471aa527 testing: fix some docstring issues
In preparation for enforcing some docstring lints.
2020-08-03 10:10:43 +03:00
Ran Benita be656dd4e4 typing: set disallow_any_generics
This prevents referring to a generic type without filling in its generic
type parameters.

The FixtureDef typing might need some more refining in the future.
2020-08-01 20:39:15 +03:00
Ran Benita 0242de4f56 Format docstrings in a consistent style 2020-08-01 17:14:37 +03:00
Bruno Oliveira 6882c0368b
Merge pull request #7593 from bluetech/typing-no-implicit-reexport
typing: set no_implicit_reexport
2020-08-01 11:03:47 -03:00
Ran Benita 8d98de8f8a typing: set no_implicit_reexport
In Python, if module A defines a name `name`, and module B does `import
name from A`, then another module C can `import name from B`.

Sometimes it is intentional -- module B is meant to "reexport" `name`.
But sometimes it is just confusion/inconsistency on where `name` should
be imported from.

mypy has a flag `--no-implicit-reexport` which puts some order into
this. A name can only be imported from a module if

1. The module defines the name
2. The module's `__all__` includes the name
3. The module imports the name as `from ... import .. as name`.

This flag is included in mypy's `--strict` flag.

I like this flag, but I realize it is a bit controversial, and in
particular item 3 above is a bit unfriendly to contributors who don't
know about it. So I didn't intend to add it to pytest.

But while investigating issue 7589 I came upon mypy issue 8754 which
causes `--no-implicit-reexport` to leak into installed libraries and
causes some unexpected typing differences *in pytest* if the user uses
this flag.

Since the diff mostly makes sense, let's just conform to it.
2020-07-31 10:09:11 +03:00
Ran Benita 96a48f0c66 Stop using more-itertools
We barely use it; the couple places that do are not really worth the
extra dependency, I think the code is clearer without it.

Also simplifies one (regular) itertools usage.

Also improves a check and an error message in `pytest.raises`.
2020-07-30 20:19:24 +03:00
Bruno Oliveira 095bf191e2
Merge pull request #7561 from nicoddemus/longreprtext-7559 2020-07-29 09:47:04 -03:00
Bruno Oliveira d3267bc49d Fix TestReport.longreprtext when TestReport.longrepr is not a string
Fix #7559
2020-07-29 09:31:15 -03:00
Ran Benita 0e0275d8d9 logging: fix capture handler level not reset on teardown after caplog.set_level()
This probably regressed in fcbaab8.
2020-07-29 14:59:29 +03:00
Ran Benita b473e515bc
Merge pull request #7541 from bluetech/py-visit
pathlib: stop using py.path.local.visit(), use os.scandir
2020-07-29 12:04:06 +03:00
Ran Benita f86e4516eb junitxml: convert from py.xml to xml.etree.ElementTree
Part of the effort to reduce dependency on the py library.

Besides that, py.xml implements its own XML serialization which is
pretty scary.

I tried to keep the code with minimal changes (though it could use some
cleanups). The differences in behavior I have noticed are:

- Attributes in the output are not sorted.

- Some unneeded escaping is no longer performed, for example escaping
  `"` to `&quot;` in a text node.
2020-07-29 10:52:21 +03:00
hp310780 27a4c6cd6d
Fix --help crash on add_ini(.., help='') and improve message on help=None (#7427) 2020-07-29 10:48:38 +03:00
Ran Benita c15bb5d3de pathlib: replace py.path.local.visit() with our own function
Part of reducing dependency on `py`. Also enables upcoming improvements.

In cases where there are simpler alternatives (in tests), I used those.

What's left are a couple of uses in `_pytest.main` and `_pytest.python`
and they only have modest requirements, so all of the featureful code
from py is not needed.
2020-07-25 00:26:49 +03:00
Zac Hatfield-Dodds 3a060b77e8
Revert change to traceback repr (#7535)
* Revert change to traceback repr

* Add test and changelog entry

* Restore *exact* prev output

Co-authored-by: Bruno Oliveira <nicoddemus@gmail.com>
2020-07-24 13:30:38 +02:00
Bruno Oliveira 7ec6401ffa
Change pytest deprecation warnings into errors for 6.0 release (#7362)
Co-authored-by: Hugo van Kemenade <hugovk@users.noreply.github.com>
2020-07-22 21:36:51 -03:00
Bruno Oliveira 2a8dcc9728
Merge pull request #7526 from bluetech/win-bash-2
testing: improve bash check
2020-07-21 23:02:05 -03:00
Ran Benita 0709305953 testing: improve bash check 2020-07-21 21:21:09 +03:00
Anthony Sottile 8616a5f1d9 Preserve newlines when captured with capfd 2020-07-20 10:31:20 -07:00
Ran Benita 41d211c24a
testing: use a tighter check if `bash` is available (#7520)
This fixes CI on Windows since GitHub Actions started installing WSL on
their images which apparently installs some wrapper `bash` which does
not run actual bash.
2020-07-20 16:24:39 +02:00
Lewis Cowles 71ab6236a1
Clearer guidance on pytest.raise(match=...) failure (#7499) 2020-07-15 22:26:47 +03:00
Bruno Oliveira e7c42ae62b
Inaccessible lock files now imply temporary directories can't be removed
Fix #7500

Co-authored-by: Ran Benita <ran@unusedvar.com>
2020-07-15 09:25:17 -03:00
Ran Benita 41c40efe80
Merge pull request #7496 from bluetech/typing-idfn
Fix typing of params ids callable form
2020-07-15 10:25:46 +03:00
Ran Benita bc17034a67 Fix typing of params ids callable form
The previous typing had an object passed to the user, which they can't
do anything with without asserting, which is inconvenient. Change it to
Any instead.

Note that what comes *back* to pytest (the return value) should be an
`object`, because we want to handle arbitrary objects without assuming
anything about them.
2020-07-14 14:53:42 +03:00
Ran Benita 91f6892e6a testing: add a file for checking no mypy errors
We probably something a bit more elaborate in the future but for now
it's something to verify fixes and catch regressions.
2020-07-14 14:37:59 +03:00
Ran Benita ccad10a829 skipping: fix dynamic xfail mark added in runtest not respected
If a test runtest phase (not setup) dynamically adds a pytest.mark.xfail
mark to the item, it should be respected, but it wasn't. This regressed
in 3e6fe92b7e (not released).

Fix it by just always refreshing the mark if needed. This is mostly what
was done before but in a more roundabout way.
2020-07-14 01:02:06 +03:00
Bruno Oliveira 07f5f6fd4a
Merge pull request #7481 from bluetech/tw-unicode-escape
terminalwriter: bring back handling of printing characters not supported by stdout
2020-07-11 16:01:45 -03:00
Simon K 7f467ebc9a
Create subdirectories if they do not exist when specified for log file (#7468)
Co-authored-by: Bruno Oliveira <nicoddemus@gmail.com>
2020-07-11 13:40:28 -03:00
Ran Benita 7b65b2337b
Merge pull request #7472 from bluetech/cleanups-4
Some minor fixes & type annotations
2020-07-11 19:05:07 +03:00
Ran Benita 113339b029 terminalwriter: bring back handling of printing characters not supported by stdout 2020-07-11 18:59:00 +03:00