Commit Graph

3247 Commits

Author SHA1 Message Date
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
Anthony Sottile 1076a7e61d
Merge pull request #5680 from ss18/ss18/pr0
Fix some typos
2019-08-01 08:18:48 -07:00
Semen Zhydenko d19fe3c410 didnt -> didn't 2019-08-01 15:10:39 +02:00
Semen Zhydenko 2de145f372 wasnt -> wasn't 2019-08-01 15:10:06 +02:00
Semen Zhydenko 942fd91995 shouldnt -> shouldn't 2019-08-01 15:09:14 +02:00
Kaiqi aa13c625da Change the warning message 2019-07-27 21:06:29 +02:00
Miro Hrončok ab39502c98 In test_xfail_handling, only remove __pycache__ if it exists
Previously, the test failed when the directory was not present,
which could have been caused for example by invoking the tests
with PYTHONDONTWRITEBYTECODE=1.

Fixes https://github.com/pytest-dev/pytest/issues/5664
2019-07-26 02:23:14 +02:00
Daniel Hahler 401c3d1109 tests: unittest: fix/harden "test_exit_outcome"
Ref: https://github.com/pytest-dev/pytest/pull/5634#pullrequestreview-265565917
2019-07-23 19:35:51 +02:00
Bruno Oliveira a82dd2f064 Fix linting 2019-07-23 10:55:22 -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 0824789459 Improve test for pytest.exit handling 2019-07-23 08:53:38 -03:00
Bruno Oliveira ec4ca59bf0
Merge pull request #5631 from RonnyPfannschmidt/fix-5606
use identity checks for the mock sentinels
2019-07-23 08:48:58 -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
Bruno Oliveira 240d314f36 copy test and changelog from #5607 by @niccodemus 2019-07-20 20:21:27 +02:00
Anthony Sottile 27c9d80a7e Fix ordering of sys modules snapshot 2019-07-20 11:17:30 -07: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 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
Bruno Oliveira 65c23017c7 Update test_getfuncargnames_patching to work with modern mock 2019-07-15 12:23:59 -03:00
Bruno Oliveira 8a3f40996a Remove obsolete "importorskip('unittest.mock')" calls 2019-07-15 11:18:05 -03: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 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 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 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 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
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
David Röthlisberger a740ef2036 docs: Document doctest +NUMBER limitation with strings
Also added an "xfail" testcase for the same.
2019-07-11 10:06:57 +01:00
David Röthlisberger 4c590e002f Fix test_doctest.test_number_non_matches
These doctests were expected to fail, but they were failing because of a
silly bug (I forgot to replace "{expression}" with the actual expression
to be tested), not because of the thing they were meant to be testing.

Then I had to fix one of the testcases because it was actually matching:

    >>> 3.0 #doctest: +NUMBER
    2.99

The doctest is saying that the actual output should match to 2 decimal
places, i.e. within 0.01 -- which it is, so it passes. I changed the
expected output to 2.98 and now it doesn't match (as we expect).
2019-07-11 09:57:44 +01: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 57e5bd0664
Improve type-checking in OutcomeException (#5580)
Improve type-checking in OutcomeException
2019-07-09 19:12:05 -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 f1b8431d99 Sort parametrize params to test_external_plugins_integrated
This might cause problems during collection with pytest-xdist; we
didn't see any so far mostly by luck I think.

Shame on me for letting that slip in.
2019-07-05 19:05:55 -03:00
Bruno Oliveira a43ba78d3b Include <testsuites> root tag in generated XML
Fix #5477
2019-07-05 11:29:35 -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