Commit Graph

1295 Commits

Author SHA1 Message Date
Ran Benita 43eab917a1 Fix coverage 2019-08-20 15:41:32 +03:00
Robert Holt 62381125e7
Fix self reference in function scoped fixtures 2019-08-19 15:57:39 -04:00
Anthony Sottile a7ede64f42 Move `@overload` to compat 2019-08-18 14:54:52 -07:00
Daniel Hahler 7c26a65865 minor: make noqa comment more specific 2019-08-17 23:48:55 +02:00
Daniel Hahler 05bfe73cf9 Fix wrong location of assertion error with coverage.py
Reverts using-constant part from 39ba99613.

Fixes https://github.com/pytest-dev/pytest/issues/5754.
2019-08-17 21:34:13 +02:00
Daniel Hahler 2a6a1ca07d Inject width via pylib to argparse formatter
`argparse.HelpFormatter` looks at `$COLUMNS` only, falling back to a
default of 80.

`py.io.get_terminal_width()` is smarter there, and could even work
better with https://github.com/pytest-dev/py/pull/219.

This ensures to use a consistent value for formatting the ini values etc.
2019-08-17 16:51:02 +02:00
Ran Benita 9f3bfe82cf Fix TypeError when importing pytest on Python 3.5.0 and 3.5.1
The typing module on these versions have these issues:

- `typing.Pattern` cannot appear in a Union since it is not considered a
  class.

- `@overload` is not supported in runtime. (On the other hand, mypy
  doesn't support putting it under `if False`, so we need some runtime
  hack).

Refs #5751.
2019-08-17 15:41:59 +03:00
Ran Benita 7259c453d6 Fix some check_untyped_defs = True mypy warnings 2019-08-16 10:41:57 +03:00
Ran Benita 28761c8da1 Have AssertionRewritingHook derive from importlib.abc.MetaPathFinder
This is nice for self-documentation, and is the type required by mypy
for adding to sys.meta_path.
2019-08-16 10:41:52 +03:00
Bruno Oliveira 1049a38cee Fix wording as suggested in review of #5741 2019-08-15 10:05:42 -03:00
Bruno Oliveira d7f082519a Merge remote-tracking branch 'upstream/master' into mm
Conflicts:
	src/_pytest/outcomes.py
2019-08-15 10:03:52 -03:00
Bruno Oliveira 2d613a03b3
Async result warn (#5742)
Async result warn
2019-08-15 09:47:56 -03:00
Bruno Oliveira 28c6c5bb71
check that tests that are partial staticmethods are supported (#5701)
check that tests that are partial staticmethods are supported
2019-08-15 09:12:01 -03:00
Thomas Grainger 6b9d729ed3
also warn on awaitable or async iterable test results 2019-08-15 12:30:44 +01:00
Bruno Oliveira 0ba774a7c3
warn for async generator functions (#5734)
warn for async generator functions
2019-08-15 08:17:12 -03:00
Thomas Grainger 137255816e Fix collection of staticmethods defined with functools.partial
Related to #5701
2019-08-15 08:04:05 -03:00
Thomas Grainger 2f1b192fe6 Issue a warning for async gen functions
Co-Authored-By: Bruno Oliveira <nicoddemus@gmail.com>
2019-08-15 07:54:10 -03:00
dmitry.dygalo 7183335e62 Capture warnings during ``pytest_configure``
Fix #5115
2019-08-15 07:50:27 -03:00
Daniel Hahler 1434b66c35 pytester: spawn: skip without pexpect.spawn
"pexpect" can be imported on Windows, but does not have "pexpect.spawn"
then.

Ref: https://github.com/pexpect/pexpect/blob/a803933ed53/pexpect/__init__.py#L73-L76
2019-08-13 17:54:40 +02:00
Daniel Hahler ed2425119f
Merge pull request #5731 from blueyed/assert-compare-maxsize
assertrepr_compare: prefer same maxsize
2019-08-12 16:02:41 +02:00
Daniel Hahler 39ba996133 assertion.rewrite: use ast.NameConstant(None) directly
`ast.parse("None")` was added/used in 3e6f1fa2d for differences between
Python 2/3, but we do not support py2 anymore.
2019-08-12 07:50:52 +02:00
Daniel Hahler cb481a354a assertrepr_compare: prefer same maxsize
Previously it would say:

    > assert '123456789012...901234567890A' == '1234567890123...901234567890B'"

This makes it look like the "3" might be different already.

This is clearer, and it is OK to have potentially one less char in the
right one:

    > assert '123456789012...901234567890A' == '123456789012...901234567890B'"
2019-08-12 03:41:14 +02:00
Bruno Oliveira 345df99db7 Show session duration in human-readable format
Fix #5707
2019-08-10 10:45:53 -03:00
Bruno Oliveira f7e81dab9a
5669: pytester: add docstrings for Testdir.copy_example (#5719)
5669: pytester: add docstrings for Testdir.copy_example
2019-08-10 09:00:42 -03:00
Ilya Stepin ee936b27a8
pytester: fix docstrings
Co-Authored-By: Bruno Oliveira <nicoddemus@gmail.com>
2019-08-10 09:12:04 +03:00
martbln e0ce8b79d5 pytester: add docstrings for Testdir.copy_example 2019-08-10 00:59:14 +03:00
Tim Hoffmann b095e0de47 Improve docs of pytest.importorskip 2019-08-09 21:35:03 +02:00
Daniel Hahler 9f6da8cbeb Remove unused function CallSpec2.setall
Fixes https://github.com/pytest-dev/pytest/issues/5253.
2019-08-09 16:34:48 +02:00
Daniel Hahler aa06e6c8f3 Merge master into features 2019-08-05 19:12:32 +02:00
Daniel Hahler 198fcd8a6f Fix RuntimeError when trying to collect package with "__init__.py" only
Fixes https://github.com/pytest-dev/pytest/issues/4344.
2019-08-05 17:52:21 +02:00
Anthony Sottile 82763a293a
Merge pull request #5684 from nicoddemus/errno-nomore
Use OSError subclasses instead of handling errno
2019-08-04 14:50:12 -07:00
Samuel Searles-Bryant 1ce45a6f67 Add hostname and timestamp to JUnit XML testsuite tag
Fix #5471
2019-08-03 15:54:39 +01:00
Bruno Oliveira d3e1907899 Use OSError subclasses instead of handling errno 2019-08-02 14:17:46 -03:00
Daniel Hahler b5b710b3ae Merge master into features
Several conflicts, mostly due to 2c402f4bd.

Conflicts:
	.pre-commit-config.yaml
	src/_pytest/outcomes.py
	src/_pytest/python_api.py
	tox.ini
2019-08-02 16:52:51 +02:00
Daniel Hahler 9064eea216 Improve rm_rf to handle only known functions
Warnings are emitted if we cannot safely remove
paths.

Fix #5626
2019-08-02 08:18:11 -03:00
Bruno Oliveira dc6e7b9fcf
Cache splitnode results to improve tests collection time (#5681)
Cache splitnode results to improve tests collection time
2019-08-01 22:32:19 -03:00
Alexey Zankevich b43ebb7d65 Cache split nodes results to reduce long tests collection time on large test suites 2019-08-01 20:46:27 -04:00
Anthony Sottile 1076a7e61d
Merge pull request #5680 from ss18/ss18/pr0
Fix some typos
2019-08-01 08:18:48 -07:00
Semen Zhydenko b3f4398d64 surpressing -> suppressing 2019-08-01 15:11:38 +02:00
Kaiqi aa13c625da Change the warning message 2019-07-27 21:06:29 +02:00
Kaiqi 6c2f673daf Have same name for fulltrace 2019-07-27 17:25:23 +02:00
Bruno Oliveira b2839c4084
Merge pull request #5646 from nicoddemus/mark-info-docs
Update MarkDecorator docs
2019-07-23 16:42:11 -03:00
Florian Bruhin 8c47db724c Improve output when parsing an ini configuration fails 2019-07-23 15:27:27 +02:00
Bruno Oliveira 693e9d0733
Merge pull request #5634 from blueyed/fix-unittest-exit
unittest: handle outcomes.Exit
2019-07-23 10:08:43 -03:00
Bruno Oliveira d66b6c8371 Update MarkDecorator docs
The MarkInfo class no longer exists
2019-07-23 08:07:38 -03:00
Daniel Hahler 3c7438969a Replace internal config._origargs with invocation_params.args
Added in https://github.com/pytest-dev/pytest/pull/5564.
2019-07-23 06:46:56 +02:00
Ronny Pfannschmidt 8c7d9124ba switch num_mock_patch_args to do identity checks for the sentinels 2019-07-20 20:21:27 +02:00
Daniel Hahler d35d09f82d unittest: handle outcomes.Exit
This is required for pytest to stop when using "quit" in pdb, and should
get honored/handled in general.
2019-07-20 07:11:49 +02:00
Ran Benita 675e9507d8 Don't accept bytes message in pytest.{fail,xfail,skip}
It seems to have been added in #1439 to fix #1178.

This was only relevant for Python 2 where it was tempting to use str (==
bytes) literals instead of unicode literals. In Python 3, it is unlikely
that anyone passes bytes to these functions.
2019-07-17 22:39:10 +03:00
Ran Benita 0b532fda76 Remove unnecessary checks from SetupState
Since 4622c28ffd, _finalizers cannot
contain Nones or tuples, so these checks are not longer needed.
2019-07-17 22:39:10 +03:00
Ran Benita 7d1c697c30 Remove a no-longer-needed check if enum is available
Not needed since 4d49ba6529.
2019-07-17 22:39:10 +03:00
Ran Benita 65aee1e0c8 Allow bytes for OutcomeException(msg=...)
It's __repr__ explicitly handles it so allow it.
2019-07-17 22:39:10 +03:00
Ran Benita 8d413c1926 Allow tuple of exceptions in ExceptionInfo.errisinstance
isinstance() accepts it and some code does pass a tuple.

Fixup for commit 55a570e513.
2019-07-17 22:39:10 +03:00
Ran Benita faf222f8fb
Merge pull request #5593 from bluetech/type-annotations-1
Type-annotate pytest.{exit,skip,fail,xfail,importorskip,warns,raises}
2019-07-16 22:38:20 +03:00
Ran Benita 9258fd1296
Merge pull request #5603 from bluetech/saferepr-simplify
Simplify SafeRepr a bit
2019-07-16 22:37:02 +03:00
Tim Hoffmann 6f1d358a0c Fix some ReST indentation issues in docstrings 2019-07-15 16:16:44 +02:00
Ran Benita 129600d698 saferepr: Avoid indirect function calls
The DRY savings they provide are rather small, while they make it harder
to type-check, and IMO harder to understand.
2019-07-15 17:07:58 +03:00
Bruno Oliveira 499fda2349
Various cleanups in src/_pytest/python.py (#5599)
Various cleanups in src/_pytest/python.py
2019-07-14 19:00:35 -03:00
Ran Benita c7aacc96bb saferepr: Remove unused setting of max_other
max_other is used by the superclass repr_instance, but we override it
and use maxsize instead.
2019-07-14 22:50:14 +03:00
Ran Benita 0394ebffee saferepr: Use an __init__ instead of setting attributes after construction
This will be easier to type-check, and also somewhat clearer.
2019-07-14 22:50:14 +03:00
Ran Benita 0225be53a2 saferepr: Remove dead SafeRepr.repr_unicode
This function is not called anywhere directly, and cannot be called by
the dynamic `repr_<type>()` dispatch mechanism because unicode is no
longer a type in Python 3.
2019-07-14 22:13:57 +03:00
Ran Benita 11f1f79222 Allow creating ExceptionInfo from existing exc_info for better typing
This way the ExceptionInfo generic parameter can be inferred from the
passed-in exc_info. See for example the replaced cast().
2019-07-14 14:28:24 +03:00
Ran Benita 3f1fb62584 Rework ExceptionInfo to not require manual __init__ call
Mypy doesn't like calling __init__() in this way.
2019-07-14 14:28:24 +03:00
Ran Benita 14bf4cdf44 Make ExceptionInfo generic in the exception type
This way, in

    with pytest.raises(ValueError) as cm:
        ...

cm.value is a ValueError and not a BaseException.
2019-07-14 14:28:24 +03:00
Ran Benita 56dcc9e1f8 Type-annotate pytest.raises 2019-07-14 14:28:24 +03:00
Ran Benita 55a570e513 Type-annotate ExceptionInfo 2019-07-14 14:28:24 +03:00
Ran Benita 2dca68b863 Type-annotate pytest.warns 2019-07-14 14:28:24 +03:00
Ran Benita d7ee3dac2c Type-annotate pytest.{exit,skip,fail,xfail,importorskip} 2019-07-14 14:28:24 +03:00
Ran Benita 866904ab80 Revert "Let context-managers for raises and warns handle unknown keyword arguments"
This reverts commit dfe54cd82f.

The idea in the commit was to simplify the code by removing the check
and instead letting it TypeError which has the same effect.

However this type error is caught by mypy, and rather than ignoring the
error we think it's better and clearer to go back to the previous
explicit check.
2019-07-14 14:28:21 +03:00
Ronny Pfannschmidt 374c4325a8 refactor finding xunit setup/teardown functions
s/_get_non_fixture_func(obj, name: str)/_get_first_non_fixture_func(obj, names: List[str])/
2019-07-13 08:13:46 +02:00
Ronny Pfannschmidt 2c071a060e refactor resolve_arg_value_types
* more explicit type checks
* expand from list+tuple to sequence
2019-07-13 08:13:46 +02:00
Bruno Oliveira 0f8b462677
Include <testsuites> root tag in generated XML (#5550)
Include <testsuites> root tag in generated XML
2019-07-12 14:35:34 -03:00
Ronny Pfannschmidt 898028cb22 remove unused _get_xunit_setup_teardown 2019-07-12 17:45:23 +02:00
Ronny Pfannschmidt 4480d3e518 generate_tests: always use call_extra
- its a noop addition in the methods is empty list
2019-07-12 17:44:17 +02:00
Ronny Pfannschmidt 13d750db20 simplify the expression which transfers mark names to keywords 2019-07-12 06:16:06 +02:00
Ronny Pfannschmidt e98627223f remove the noop init of PyobjMixin 2019-07-12 06:14:36 +02:00
Albert Tugushev c89e379f49 Fix typos 2019-07-12 02:35:44 +03:00
Bruno Oliveira 24a66db8d3 Remove support code for unittest 2
Also moved a pytest_runtest_makereport hook implemented in
nose.py, but nowadays makes more sense to be implemented in
unittest.py
2019-07-11 20:11:06 -03:00
Bruno Oliveira 37c37963c4 Fix rmtree to remove directories with read-only files
Fix #5524
2019-07-11 18:24:53 -03:00
Bruno Oliveira 666acc9b7a
doctest: Add +NUMBER option to ignore irrelevant floating-point… (#5576)
doctest: Add +NUMBER option to ignore irrelevant floating-point differences
2019-07-11 07:25:37 -03:00
Ran Benita f7747f5dd6 Remove references to old-style classes in a couple error messages
These don't exist in Python 3.
2019-07-10 20:25:45 +03:00
Bruno Oliveira 2c402f4bd9
[cherry-pick to master] Add rudimentary mypy type checking (#5583)
[cherry-pick to master] Add rudimentary mypy type checking
2019-07-10 07:52:32 -03:00
Bruno Oliveira 602cd5e21f
Introduce Config.invocation_params (#5564)
Introduce Config.invocation_params
2019-07-10 07:46:34 -03:00
Bruno Oliveira 31738155b5
Remove deprecated features (#5529)
Remove deprecated features
2019-07-09 19:04:06 -03:00
Bruno Oliveira 9db1823707 Improve type-checking in OutcomeException
Fix #5578
2019-07-09 18:26:57 -03:00
Ran Benita 89dfde9535 Add rudimentary mypy type checking
Add a very lax mypy configuration, add it to tox -e linting, and
fix/ignore the few errors that come up. The idea is to get it running
before diving in too much.

This enables:

- Progressively adding type annotations and enabling more strict
  options, which will improve the codebase (IMO).

- Annotating the public API in-line, and eventually exposing it to
  library users who use type checkers (with a py.typed file).

Though, none of this is done yet.

Refs https://github.com/pytest-dev/pytest/issues/3342.
2019-07-09 12:12:07 -07:00
Anthony Sottile 39a43dbae1
Merge pull request #5575 from bluetech/mypy-initial
Add rudimentary mypy type checking
2019-07-09 08:05:14 -07:00
Ran Benita c1167ac552 Add rudimentary mypy type checking
Add a very lax mypy configuration, add it to tox -e linting, and
fix/ignore the few errors that come up. The idea is to get it running
before diving in too much.

This enables:

- Progressively adding type annotations and enabling more strict
  options, which will improve the codebase (IMO).

- Annotating the public API in-line, and eventually exposing it to
  library users who use type checkers (with a py.typed file).

Though, none of this is done yet.

Refs https://github.com/pytest-dev/pytest/issues/3342.
2019-07-09 10:49:17 +03:00
David Röthlisberger aaa7e837cc doctest: Add +NUMBER option to ignore irrelevant floating-point differences
When enabled, floating-point numbers only need to match as far as the
precision you have written in the expected doctest output. This avoids
false positives caused by limited floating-point precision, like this:

    Expected:
        0.233
    Got:
        0.23300000000000001

This is inspired by Sébastien Boisgérault's [numtest] but the
implementation is a bit different:

* This implementation edits the literals that are in the "got"
  string (the actual output from the expression being tested), and then
  proceeds to compare the strings literally. This is similar to pytest's
  existing ALLOW_UNICODE and ALLOW_BYTES implementation.

* This implementation only compares floats against floats, not ints
  against floats. That is, the following doctest will fail with pytest
  whereas it would pass with numtest:

      >>> math.py  # doctest: +NUMBER
      3

  This behaviour should be less surprising (less false negatives) when
  you enable NUMBER globally in pytest.ini.

Advantages of this implementation compared to numtest:

* Doesn't require `import numtest` at the top level of the file.
* Works with pytest (if you try to use pytest & numtest together, pytest
  raises "TypeError: unbound method check_output() must be called with
  NumTestOutputChecker instance as first argument (got
  LiteralsOutputChecker instance instead)").
* Works with Python 3.

[numtest]: https://github.com/boisgera/numtest
2019-07-08 17:07:58 +01:00
Bruno Oliveira 4cda7093f6 Add note about PYTEST_ADDOPTS 2019-07-06 17:27:54 -03:00
Bruno Oliveira 6a9bf2852a Apply review suggestions: use a simple struct for invocation params 2019-07-06 12:22:19 -03:00
Bruno Oliveira 3e669a262a Introduce Config.invocation_args and Config.invocation_plugins
These attributes can be used to access the unchanged arguments passed
to pytest.main().

The intention is to use these attributes to initialize workers in
the same manner as the master node is initialized in pytest-xdist.
2019-07-05 19:45:23 -03:00
Bruno Oliveira a43ba78d3b Include <testsuites> root tag in generated XML
Fix #5477
2019-07-05 11:29:35 -03:00
Bruno Oliveira 0371a3023a Fix comment in stepwise (follow up to #5555) [skip ci] 2019-07-05 09:57:10 -03:00
Bruno Oliveira d7588b8d40 Merge remote-tracking branch 'upstream/master' into merge-master-into-features 2019-07-05 08:14:18 -03:00
Bruno Oliveira 8651d880a0 Handle xfail(strict=True) properly in --step-wise mode
Fix #5547
2019-07-04 20:28:37 -03:00
Miro Hrončok c54cbd63c8 Replace importlib_metadata with importlib.metadata on Python 3.8+
Fixes https://github.com/pytest-dev/pytest/issues/5537
2019-07-04 15:00:10 +02:00
Bruno Oliveira 1db132290f Apply workaround for multiple short options for Python <= 3.8
Hopefully by Python 3.9 this will be fixed upstream, if not we will
need to bump the version again.

Fix #5523
2019-07-04 14:59:40 +02:00
Anthony Sottile caa08ebd45 Improve quoting in raises match failure message 2019-07-04 05:55:26 -07:00
Bruno Oliveira dfe54cd82f Let context-managers for raises and warns handle unknown keyword arguments
As suggested during review
2019-07-03 13:57:28 -03:00