Commit Graph

4098 Commits

Author SHA1 Message Date
Ronny Pfannschmidt 4e5a7b7d2f
Merge pull request #7366 from gnikonorov/issue_7346
Allow users to provide version information to the required_plugins INI key
2020-06-15 20:19:05 +02:00
Gleb Nikonorov 320625527a Add more tests and docs 2020-06-13 11:22:18 -04:00
Bruno Oliveira ab6dacf1d1
Introduce --import-mode=importlib (#7246)
Fix #5821

Co-authored-by: Ran Benita <ran@unusedvar.com>
2020-06-13 11:29:01 -03:00
Bruno Oliveira 2c37585f58
Merge pull request #7258 from piotrhm/issue_6471 2020-06-13 11:14:18 -03:00
Gleb Nikonorov 7ea116d74c Merge remote-tracking branch 'origin' into issue_7346 2020-06-13 09:54:23 -04:00
Bruno Oliveira 3151219785 assertoutcomes() only accepts plural forms
Fix #6505
2020-06-13 10:29:22 -03:00
Ran Benita f551cab877
Merge pull request #7358 from bluetech/typing2
More type annotations, fix some typing bugs
2020-06-13 10:44:11 +03:00
Gleb Nikonorov 6f8633cc17 add in solution barring documentation 2020-06-13 02:47:15 -04:00
Bruno Oliveira aaa6f1c3fa
Merge pull request #7330 from gnikonorov/issue_7305 2020-06-12 19:35:38 -03:00
Ran Benita 1cf9405075 Fix some type errors around py.path.local
These errors are found using a typed version of py.path.local.
2020-06-12 17:34:31 +03:00
Ran Benita b4f046b777 monkeypatch: add type annotations 2020-06-12 17:34:31 +03:00
Ran Benita f84ffd9747 Remove unused type: ignores
Not needed since update from mypy 0.770 -> 0.780.
2020-06-12 17:34:31 +03:00
Zac Hatfield-Dodds 0f30103d9c
Merge pull request #7356 from Zac-HD/emancipate
Finish deprecation of "slave"
2020-06-12 23:13:11 +10:00
Zac-HD 564b2f707d Finish deprecation of "slave" 2020-06-12 22:49:33 +10:00
Bruno Oliveira ab331c906e Suppress errors while removing tmpdir's lock files
Fix #5456
2020-06-11 18:59:51 -03:00
Gleb Nikonorov 95cb7fb676 review feedback 2020-06-10 00:44:22 -04:00
Bruno Oliveira c229d6f46f Fix mypy checks 2020-06-09 14:48:49 -03:00
Ran Benita 09988f3ed1 Update testing/test_assertion.py 2020-06-09 14:39:40 -03:00
ibriquem e2e7f15b71 Make dataclasses/attrs comparison recursive, fixes #4675 2020-06-09 14:39:40 -03:00
piotrhm df562533ff Fixed test 2020-06-08 22:26:14 -03:00
piotrhm 2be1c61eb3 Fixed linting 2 2020-06-08 22:26:14 -03:00
piotrhm 5e0e12d69b Fixed linting 2020-06-08 22:26:14 -03:00
piotrhm 51fb11c1d1 Added tests 2020-06-08 22:26:14 -03:00
Bruno Oliveira fcbaab8b0b
Allow tests to override "global" `log_level` (rebased) (#7340)
Co-authored-by: Ruaridh Williamson <ruaridh.williamson@flexciton.com>
2020-06-08 22:05:46 -03:00
Prashant Anand e78207c936
7119: data loss with mistyped --basetemp (#7170)
Co-authored-by: Bruno Oliveira <nicoddemus@gmail.com>
Co-authored-by: Ran Benita <ran@unusedvar.com>
2020-06-08 21:54:22 -03:00
Fabio Zadrozny 322190fd84
Fix issue where working dir becomes wrong on subst drive on Windows. Fixes #5965 (#6523)
Co-authored-by: Bruno Oliveira <nicoddemus@gmail.com>
2020-06-08 10:56:40 -03:00
Bruno Oliveira c17d50829f
Add pyproject.toml support (#7247) 2020-06-08 10:03:10 -03:00
Gleb Nikonorov f1746c50ea Merge remote-tracking branch 'origin/master' into issue_7305 2020-06-06 12:37:56 -04:00
Gleb Nikonorov 2a3c21645e Commit solution thus far, needs to be polished up pre PR 2020-06-06 02:38:18 -04:00
Ran Benita 1deaa74345 mark/expression: prevent creation of illegal Python identifiers
This is rejected by Python DEBUG builds, as well as regular builds in
future versions.
2020-06-05 15:57:48 +03:00
Ran Benita 54ad048be7 Enable check_untyped_defs mypy option for testing/ too 2020-06-05 11:34:20 +03:00
Ran Benita 2833884688 Type annotate pytest.fixture and more improvements to _pytest.fixtures 2020-06-05 11:34:20 +03:00
Ran Benita 90e58f8961 Type annotate some parts related to runner & reports 2020-06-05 11:34:20 +03:00
Ran Benita d95132178c Type annotate _pytest.assertion 2020-06-05 11:34:19 +03:00
Ran Benita 247c4c0482 Type annotate some more hooks & impls 2020-06-05 11:34:19 +03:00
Ran Benita ef34729541 Type annotate fixtures.py & related 2020-06-05 11:34:19 +03:00
Ran Benita ff8b7884e8 Type annotate ParameterSet 2020-06-05 11:34:19 +03:00
Ran Benita 2e219ad4f3 testing: change a test to not use deprecated pluggy __multicall__ protocol
It is slated to be removed in pluggy 1.0.
2020-06-03 21:51:55 +03:00
Bruno Oliveira 61a6ac9705
Merge pull request #7242 from nicoddemus/fix-flaky-test
Introduce _pytest.timing as a way to control timing during internal tests
2020-06-02 20:25:02 -03:00
Bruno Oliveira 8ac18bbecb Show invalid ini keys sorted
Otherwise this relies on the dictionary order of `config.inicfg`, which
is insertion order in py36+ but "random" order in py35.
2020-06-02 16:01:47 -03:00
Bruno Oliveira 7a8b8a5c9f
Merge branch 'master' into fix-flaky-test 2020-06-02 11:33:15 -03:00
Ronny Pfannschmidt 8faf1e8eca
Merge pull request #7286 from gnikonorov/issue_6856
Output a warning to stderr when an invalid key is read from an INI config file
2020-06-02 15:47:02 +02:00
Tor Colvin fe64093411
Fix removal of very long paths on Windows (#6755)
Co-authored-by: Bruno Oliveira <nicoddemus@gmail.com>
2020-06-02 08:56:33 -03:00
Bruno Oliveira 70b5bdf4ba
Merge pull request #7264 from bluetech/wcwidth
Improve our own wcwidth implementation and remove dependency on wcwidth package
2020-05-31 12:37:58 -03:00
Ronny Pfannschmidt c16ede5ce6
Merge pull request #7255 from gnikonorov/issue_4049
Add new hook pytest_warning_recorded
2020-05-31 12:47:46 +02:00
Gleb Nikonorov db203afba3 Add in --strict-config flag to force warnings to errors 2020-05-31 02:45:40 -04:00
Gleb Nikonorov 8f2c2a5dd9 Add test case for invalid ini key in different section header 2020-05-31 00:49:21 -04:00
Gleb Nikonorov eef4f87e7b Output a warning to stderr when an invalid key is read from an INI config file 2020-05-30 20:36:02 -04:00
Bruno Oliveira b98aa195e0 Add test and changelog for #6428 2020-05-30 20:02:47 -03:00
Bruno Oliveira 56bf819c2f
Do not call TestCase.tearDown for skipped tests (#7236)
Fix #7215
2020-05-30 14:33:22 -03:00
Katarzyna Król 94c7b8b47c
Issue 1316 - longrepr is a string when pytrace=False (#7100) 2020-05-30 14:10:58 +03:00
Gleb Nikonorov 2af0d1e221 remove a stray comma in a test tuple 2020-05-28 00:02:28 -04:00
Gleb Nikonorov 14de08011b fix the unit tests, add the proper deprecation warning, and add in a changelog entry 2020-05-27 23:03:07 -04:00
Anthony Sottile b3db440d4c
Merge pull request #7257 from DahlitzFlorian/fix-issue-6956
Prevent pytest from printing ConftestImportFailure traceback
2020-05-27 13:49:43 -07:00
Ran Benita f93e021bc8 capture: remove some unclear parametrization from a test
The two cases end up doing the same (the tmpfile fixture isn't used
except being truthy).
2020-05-27 15:27:16 +03:00
Ran Benita a35800c2e1 capture: formalize and check allowed state transition in capture classes
There are state transitions start/done/suspend/resume and two additional
operations snap/writeorg.

Previously it was not well defined in what order they can be called, and
which operations are idempotent.

Formalize this and enforce using assert checks with informative error
messages if they fail (rather than random AttributeErrors).
2020-05-27 15:27:15 +03:00
Florian Dahlitz 5b9924e144
Fix py35 CI run 2020-05-27 09:27:13 +02:00
Gleb Nikonorov d742b386c3 provide missing location parameter, and add type annotations to the hookspec 2020-05-27 00:53:31 -04:00
Ran Benita aca534c67d Improve our own wcwidth implementation and remove dependency on wcwidth package
`TerminalWriter`, imported recently from `py`, contains its own
incomplete wcwidth (`char_with`/`get_line_width`) implementation. The
`TerminalReporter` also needs this, but uses the external `wcwidth`
package.

This commit brings the `TerminalWriter` implementation up-to-par with
`wcwidth`, moves to implementation to a new file `_pytest._io.wcwidth`
which is used everywhere, and removes the dependency.

The differences compared to the `wcwidth` package are:

- Normalizes the string before counting.

- Uses Python's `unicodedata` instead of vendored Unicode tables. This
  means the data corresponds to the Python's version Unicode version
  instead of the `wcwidth`'s package version.

- Apply some optimizations.
2020-05-26 17:14:01 +03:00
Florian Dahlitz 95bd232e57
Apply suggestions from @bluetech 2020-05-26 10:31:53 +02:00
Ran Benita ea3f44894f capture: replace TeeSysCapture with SysCapture(tee=True)
This is more straightforward and does not require duplicating the
initialization logic.
2020-05-26 00:25:49 +03:00
Ran Benita 491239d9b2 capture: remove some indirection in MultiCapture
Removing this indirection enables some further clean ups.
2020-05-26 00:25:49 +03:00
Florian Dahlitz 6546d1f725
Prevent pytest from printing ConftestImportFailure traceback 2020-05-25 13:57:03 +02:00
Gleb Nikonorov 088d400b2d rename pytest_warning_record -> pytest_warning_recorded 2020-05-24 20:43:23 -04:00
Gleb Nikonorov 9ee6550181 Add in a new hook pytest_warning_recorded for warning capture
communication
2020-05-24 19:05:24 -04:00
Anthony Sottile 45f53266e6
Merge pull request #7244 from DahlitzFlorian/fix-issue-7150
Prevent hiding underlying exception when ConfTestImportFailure is raised
2020-05-23 12:09:42 -07:00
Florian Dahlitz 35e6dd0117
Add test for exposure of underlying exception 2020-05-23 18:19:33 +02:00
Bruno Oliveira 1780924b27 Introduce _pytest.timing as a way to control timing during tests
_pytest.timing is an indirection to 'time' functions, which pytest production
code should use instead of 'time' directly.

'mock_timing' is a new fixture which then mocks those functions, allowing us
to write time-reliable tests which run instantly and are not flaky.

This was triggered by recent flaky junitxml tests on Windows related to timing
issues.
2020-05-23 11:50:33 -03:00
Claire Cecil 79701c65ed
Added support for less verbose version information (#7169) 2020-05-23 11:27:58 -03:00
Ran Benita 4a1557fa0e
Merge pull request #7091 from bluetech/capture-invalid-fd
Perform FD capturing even if the FD is invalid
2020-05-22 14:36:49 +03:00
Ran Benita 919ac2239d
Merge pull request #7231 from bluetech/logging-error
logging: propagate errors during log message emits
2020-05-22 14:27:26 +03:00
Ran Benita eaeafd7c30 Perform FD capturing even if the FD is invalid
The `FDCapture`/`FDCaptureBinary` classes, used by `capfd`/`capfdbinary`
fixtures and the `--capture=fd` option (set by default), redirect FDs
1/2 (stdout/stderr) to a temporary file. To do this, they need to save
the old file by duplicating the FD before redirecting it, to be restored
once finished.

Previously, if this duplicating (`os.dup()`) failed, most likely due to
that FD being invalid, the FD redirection would silently not be done. The
FD capturing also performs python-level redirection (monkeypatching
`sys.stdout`/`sys.stderr`) which would still be done, but direct writes
to the FDs would fail.

This is not great. If pytest is run with `--capture=fd`, or a test is
using `capfd`, it expects writes to the FD to work and be captured,
regardless of external circumstances.

So, instead of disabling FD capturing, keep the redirection to a
temporary file, just don't restore it after closing, because there is
nothing to restore to.
2020-05-20 19:32:37 +03:00
Bruno Oliveira 0a03217903
Merge pull request #7046 from blueyed/k-skip-session-upstream 2020-05-19 20:09:36 -03:00
Daniel Hahler 35d136161a add test
Fixes the test to not match e.g. hypothesis (ref: bdde2ac28).

Conflicts:
	testing/test_helpconfig.py
2020-05-19 19:34:08 -03:00
Bruno Oliveira 55099e57c3 Add requested comment as per review 2020-05-19 19:20:41 -03:00
Daniel Hahler b98a182aa1 (no) coverage 2020-05-19 19:20:41 -03:00
Daniel Hahler 61180eec93 Test behavior of Source with regard to decorators
Unlinke `inspect.getsource` it does not unwrap functions.
2020-05-19 19:20:41 -03:00
Bruno Oliveira 5a6296a2d7
Merge pull request #7226 from nicoddemus/remove-function-args 2020-05-19 18:53:23 -03:00
Ran Benita b13fcb23d7 logging: propagate errors during log message emits
Currently, a bad logging call, e.g.

    logger.info('oops', 'first', 2)

triggers the default logging handling, which is printing an error to
stderr but otherwise continuing.

For regular programs this behavior makes sense, a bad log message
shouldn't take down the program. But during tests, it is better not to
skip over such mistakes, but propagate them to the user.
2020-05-19 11:16:39 +03:00
Ran Benita 85a06cfafb
Merge pull request #7227 from bluetech/logging-reuse-handler
logging: reuse LoggingCaptureHandler instance since it's expensive to create
2020-05-18 23:16:51 +03:00
Bruno Oliveira ad3169428b Remove unused Function.__init__ 'args' parameter 2020-05-18 14:30:48 -03:00
Daniel Hahler 8b9b81c3c0
Function: use `originalname` in `_getobj` and make it default to `name` (#7035) 2020-05-18 14:08:47 -03:00
Ran Benita d2d11a8bdc logging: reuse LoggingCaptureHandler instance since it's expensive to create
Previously, a LoggingCaptureHandler was instantiated for each test's
setup/call/teardown which turns out to be expensive.

Instead, only keep one instance and reset it between runs.
2020-05-18 11:27:50 +03:00
Anthony Sottile 9310d67773
Merge pull request #7003 from blueyed/tests-reload-upstream
tests: revisit tests for removed load_module
2020-05-17 14:36:13 -07:00
Daniel Hahler 18bc706fdc tests: revisit tests for removed load_module
The tests came via c629f6b18 and c61ff31ffa.
The fixes from there are kind of obsoleted by 4cd08f9 (moving to importlib),
but it makes sense to keep them as integration tests in general.
2020-05-17 14:16:43 -07:00
Ran Benita e27228a4e4
Merge pull request #7224 from bluetech/logging-simplifications
logging: some simplifications/cleanups
2020-05-18 00:15:59 +03:00
Ran Benita 3f8200676f logging: remove deprecated --no-print-logs option/ini
This option was deprecated in 5.4.0 and was marked for removal in 6.0.0.
2020-05-17 21:41:38 +03:00
Ran Benita ac6c02f1e2 logging: use item's store for private attributes
This makes things type-safe and properly private.
2020-05-17 20:42:05 +03:00
Bruno Oliveira 9e1e7fcabe Use a nice string repr for ConftestImportFailure
The default message is often hard to read:

    E   _pytest.config.ConftestImportFailure: (local('D:\\projects\\pytest\\.tmp\\root\\foo\\conftest.py'), (<class 'RuntimeError'>, RuntimeError('some error',), <traceback object at 0x000001CCC3E39348>))

Using a shorter message is better:

    E   _pytest.config.ConftestImportFailure: RuntimeError: some error (from D:\projects\pytest\.tmp\root\foo\conftest.py)

And we don't really lose any information due to exception chaining.
2020-05-17 11:26:30 -03:00
Bruno Oliveira c5b367b4f4 Package.name now contains only basname of the package
Previously it contained the entire path, which made '-k' match
against any name in the full path of the package.

Fix #7040
2020-05-16 15:04:07 -03:00
Bruno Oliveira f506682abe
Merge pull request #6919 from nicoddemus/backport-6914 2020-05-16 12:42:15 -03:00
Daniel Hahler d530d70128 Fix regressions with `--lf` plugin
Only filter with known failures, and explicitly keep paths of passed
arguments.

This also displays the "run-last-failure" status before collected files,
and does not update the cache with "--collect-only".

Fixes https://github.com/pytest-dev/pytest/issues/6968.
2020-05-15 18:35:38 -03:00
Ran Benita f0f552d60c
Merge pull request #6283 from felixn/master
Create LogCaptureHandler if necessary (closes #6240)
2020-05-15 09:13:57 +03:00
Ran Benita 2ac28f6c65
Merge pull request #7205 from lancelote/7126
Issue 7126 - "saferepr" to avoid BytesWarning when using --setup-show
2020-05-14 16:04:22 +03:00
Felix Nieuwenhuizen 4dfc461036 Create LogCaptureHandler if necessary (closes #6240) 2020-05-13 20:38:14 +02:00
Ran Benita c714f05ad7 mark: reuse compiled expression for all items in -k/-m
The previous commit made this possible, so utilize it.

Since legacy.py becomes pretty bare, I inlined it into __init__.py. I'm
not sure it's really "legacy" anyway!

Using a simple 50000 items benchmark with `--collect-only -k nomatch`:

Before (two commits ago):

   ======================== 50000 deselected in 10.31s =====================
         19129345 function calls (18275596 primitive calls) in 10.634 seconds

   Ordered by: cumulative time

   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
        1    0.001    0.001    2.270    2.270 __init__.py:149(pytest_collection_modifyitems)
        1    0.036    0.036    2.270    2.270 __init__.py:104(deselect_by_keyword)
    50000    0.055    0.000    2.226    0.000 legacy.py:87(matchkeyword)

After:

   ======================== 50000 deselected in 9.37s =========================
         18029363 function calls (17175972 primitive calls) in 9.701 seconds

   Ordered by: cumulative time

   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
        1    0.000    0.000    1.394    1.394 __init__.py:239(pytest_collection_modifyitems)
        1    0.057    0.057    1.393    1.393 __init__.py:162(deselect_by_keyword)

The matching itself can be optimized more but that's a different story.
2020-05-12 12:55:37 +03:00
Ran Benita 622c4ce02e mark/expression: support compiling once and reusing for multiple evaluations
In current pytest, the same expression is matched against all items. But
it is re-parsed for every match.

Add support for "compiling" an expression and reusing the result. Errors
may only occur during compilation.

This is done by parsing the expression into a Python `ast.Expression`,
then `compile()`ing it into a code object. Evaluation is then done using
`eval()`.

Note: historically we used to use `eval` directly on the user input --
this is not the case here, the expression is entirely under our control
according to our grammar, we just JIT-compile it to Python as a
(completely safe) optimization.
2020-05-12 12:53:12 +03:00
Ran Benita 59a12e9ab3 Replace bare `except`s with `except BaseException`
Mostly I wanted to remove uses of `noqa`.

In Python 3 the two are the same.
2020-05-12 09:29:47 +03:00
Ran Benita d1534181c0 pre-commit: upgrade flake8 3.7.7 -> 3.8.1
New errors:

    testing/test_setupplan.py:104:15: E741 ambiguous variable name 'l'
    testing/test_setupplan.py:107:15: E741 ambiguous variable name 'l'
    extra/get_issues.py:48:29: E741 ambiguous variable name 'l'
    testing/test_error_diffs.py:270:32: E741 ambiguous variable name 'l'

Not so sure about it but easier to just fix.

But more importantly, is a large amount of typing-related issues there
were fixed which necessitated noqa's which can now be removed.
2020-05-12 09:29:40 +03:00
Ran Benita c4f9eaa5de mark: deprecate a couple undocumented -k syntaxes
The `-k '-expr'` syntax is an old alias to `-k 'not expr'`. It's also
not a very convenient to have syntax that start with `-` on the CLI.
Deprecate it and suggest replacing with `not`.

---

The `-k 'expr:'` syntax discards all items until the first match and
keeps all subsequent, e.g. `-k foo` with

    test_bar
    test_foo
    test_baz

results in `test_foo`, `test_baz`. That's a bit weird, so deprecate it
without a replacement. If someone complains we can reconsider or devise
a better alternative.
2020-05-11 16:07:52 +03:00
Pavel Karateev 8bd3f1a72b
Better test method name
Co-authored-by: Ran Benita <ran@unusedvar.com>
2020-05-10 16:59:20 +03:00
Pavel Karateev 184528d0c2 Fix tests to expected repr output 2020-05-10 13:06:36 +03:00
Pavel Karateev 6b26f0f890 Rename test method and reference issue 2020-05-10 12:19:52 +03:00
Pavel Karateev 903e2ab6ee Fix #7126 - saferepr for bytes params
bytes parametrize parameters cause error when --setup-show is used
and Python is called with -bb flag
2020-05-09 13:57:17 +03:00
Bruno Oliveira b02b0b610b
Merge pull request #6989 from blueyed/fix-test 2020-05-08 09:04:59 -03:00
Bruno Oliveira 5dd987e10f
Merge pull request #6999 from bluetech/simplify-fixture-compat 2020-05-08 08:06:35 -03:00
Bruno Oliveira 9657798c12
Merge pull request #7158 from CarycaKatarzyna/issue_7076 2020-05-08 07:56:03 -03:00
Ran Benita 857b5c9ccd
Merge pull request #7185 from bluetech/sigpipe
Handle SIGPIPE/BrokenPipeError in pytest's CLI
2020-05-08 13:32:34 +03:00
Ran Benita 73448f265d Handle EPIPE/BrokenPipeError in pytest's CLI
Running `pytest | head -1` and similar causes an annoying error to be
printed to stderr:

    Exception ignored in: <_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'>
    BrokenPipeError: [Errno 32] Broken pipe

(or possibly even a propagating exception in older/other Python versions).

The standard UNIX behavior is to handle the EPIPE silently. To
recommended method to do this in Python is described here:
https://docs.python.org/3/library/signal.html#note-on-sigpipe

It is not appropriate to apply this recommendation to `pytest.main()`,
which is used programmatically for in-process runs. Hence, change
pytest's entrypoint to a new `pytest.console_main()` function, to be
used exclusively by pytest's CLI, and add the SIGPIPE code there.

Fixes #4375.
2020-05-08 12:51:02 +03:00
Anthony Sottile 9d2eabb397
Merge pull request #7186 from asottile/is_setup_py_encoding_agnostic
Fix _is_setup_py for files encoded differently than locale
2020-05-07 14:01:28 -07:00
Bruno Oliveira 63e94b986b
Merge pull request #7179 from asottile/py39 2020-05-07 17:42:57 -03:00
Anthony Sottile b238845d0f Fix _is_setup_py for files encoded differently than locale 2020-05-07 13:14:58 -07:00
Ran Benita de556f895f
testing: clean up parametrization in test_mark.py (#7184) 2020-05-07 20:42:04 +03:00
Anthony Sottile dad328bc8a Fix tests for python3.9 2020-05-07 05:26:55 -07:00
Ran Benita 81da5dac48
Merge pull request #7122 from bluetech/matcher-parser
Stop using Python's eval() for -m and -k
2020-05-07 09:23:29 +03:00
Bruno Oliveira 6c2d358918
Merge pull request #7135 from pytest-dev/terminalwriter 2020-05-06 18:26:44 -03:00
Bruno Oliveira d0022b5a13 'saferepr' handles classes with broken __getattribute__
Fix #7145
2020-05-05 19:22:39 -03:00
Ran Benita abf785666a testing: fix lint after merge of old branch 2020-05-05 22:00:55 +03:00
Ran Benita 4b91617002
Merge pull request #7020 from blueyed/fix-warnings-summary
Fix warnings summary
2020-05-05 21:58:57 +03:00
Ran Benita a8dbb32a6b
Merge pull request #6797 from blueyed/tests-simpler
tests: simplify test_pytest_plugins_in_non_top_level_conftest_…
2020-05-05 21:51:50 +03:00
Ran Benita b4be6cd4b7
Merge pull request #6765 from blueyed/capture-refactor-1
Refactor Capture classes: move/rename CaptureIO classes
2020-05-05 21:46:18 +03:00
Daniel Hahler 8cae78a18b Fix warnings summary
- replace "tests with warnings" with just warnings: they a) might not
  come from a test in the first place, and b) a single test might have
  multiple warnings.
- fix usage of (unused) argument to `collapsed_location_report`

Co-authored-by: Ran Benita <ran@unusedvar.com>
2020-05-05 21:40:34 +03:00
Ran Benita d7d627b1e8
Merge pull request #7064 from blueyed/fix-_printcollecteditems-doc-upstream
Fix/improve printing of docs for collected items
2020-05-05 21:31:21 +03:00
Daniel Hahler 7647d1c836 Move Capture classes from compat to capture and improve naming
Move {Passthrough,CaptureIO} to capture module, and rename Passthrough
-> Tee to match the existing terminology.

Co-authored-by: Ran Benita <ran@unusedvar.com>
2020-05-05 21:24:59 +03:00
Ran Benita 46d768503e
Merge pull request #6839 from blueyed/typing-get_dirs_from_args-parseconfig
typing: get_dirs_from_args, parseconfig
2020-05-05 21:11:26 +03:00
Ran Benita b4c46da278
Merge pull request #7029 from blueyed/fix-test_popen_default_stdin_stderr_and_stdin_None-upstream
Fix `test_popen_default_stdin_stderr_and_stdin_None` when run with `-s`
2020-05-05 21:03:04 +03:00
Katarzyna 9b423710aa Remove unnecessary file in test. 2020-05-04 00:34:19 +02:00
Katarzyna a5bcd0655f Test relapth when rootdir != invocationdir. 2020-05-04 00:04:38 +02:00
Bruno Oliveira 80e5098408
Merge pull request #7155 from kerizane/make_numbered_dir 2020-05-03 09:48:36 -03:00
Keri Volans 678440e46d 7018: Use internal version of make_numbered_dir 2020-05-03 10:45:06 +01:00
Bruno Oliveira 82f584b5a9 Fix test_trial_error in test_unittest
This reverts the test to the state before 04f27d4, which introduced the breaking
change about addCleanup not being called properly for failed tests.
2020-05-02 15:26:55 -03:00
Bruno Oliveira 5c2e96c0e6 Fix cleanup functions not being invoked on test failures
Also delay calling tearDown() when --pdb is given, so users still have
access to the instance variables (which are usually cleaned up during tearDown())
when debugging.

Fix #6947
2020-05-02 15:26:55 -03:00
Bruno Oliveira 0b78983197
Merge pull request #7141 from bluetech/rm-nonzero 2020-05-02 10:00:35 -03:00
Bruno Oliveira e3643751bc
Merge pull request #7144 from nicoddemus/async-testcase-7110 2020-05-01 16:44:10 -03:00
Bruno Oliveira fd2f172258 Let unittest frameworks deal with async functions
Instead of trying to handle unittest-async functions in pytest_pyfunc_call,
let the unittest framework handle them instead.

This lets us remove the hack in pytest_pyfunc_call, with the upside that
we should support any unittest-async based framework.

Also included 'asynctest' as test dependency for py37-twisted, and renamed
'twisted' to 'unittestextras' to better reflect that we install 'twisted' and
'asynctest' now.

This also fixes the problem of cleanUp functions not being properly called
for async functions.

Fix #7110
Fix #6924
2020-05-01 15:10:28 -03:00
Bruno Oliveira 7f5978c34c Allow File.from_parent to forward custom parameters to the constructor 2020-05-01 11:00:52 -03:00
Ran Benita a718ad6363 Stop using Python's eval() for -m and -k
Previously, the expressions given to the `-m` and `-k` options were
evaluated with `eval`. This causes a few issues:

- Python keywords cannot be used.

- Constants like numbers, None, True, False are not handled correctly.

- Various syntax like numeric operators and `X if Y else Z` is supported
  unintentionally.

- `eval()` is somewhat dangerous for arbitrary input.

- Can fail in many ways so requires `except Exception`.

The format we want to support is quite simple, so change to a custom
parser. This fixes the issues above, and gives us full control of the
format, so can be documented comprehensively and even be extended in the
future if we wish.
2020-05-01 12:59:06 +03:00
Ran Benita 409ffcef17 Remove a couple Python 2 __nonzero__ definitions
It's called __bool__ in Python 3.
2020-05-01 11:41:21 +03:00
Ran Benita d8558e87c5 terminalwriter: clean up markup function a bit 2020-04-30 16:44:03 +03:00
Ran Benita 414a87a53f config/argparsing: use our own get_terminal_width() 2020-04-30 16:44:03 +03:00
Ran Benita bafc9bd58b testing: merge code/test_terminal_writer.py into io/test_terminalwriter.py 2020-04-30 16:44:03 +03:00
Ran Benita 0e36596268 testing/io: port TerminalWriter tests from py 2020-04-30 16:44:03 +03:00
Ran Benita 66ee755649 terminalwriter: remove TerminalWriter's stringio argument
Had a mark indicating it should be removed, and I agree, it's better to
just use the `file` argument.
2020-04-30 16:44:02 +03:00
Ran Benita e5d6e58625
Merge pull request #7130 from bluetech/cacheprovider-nf-set
cacheprovider: speed up NFPlugin when --nf is not enabled
2020-04-29 17:28:20 +03:00
Ran Benita 077d1c3502
Merge pull request #7129 from bluetech/testing-cache-writefail-warning
testing: fix warning issued by test_cache_writefail_cachfile_silent
2020-04-29 16:00:43 +03:00
Ran Benita 4a42afdc2f cacheprovider: speed up NFPlugin when --nf is not enabled
The code used an O(n^2) loop. Replace list with set to make it O(n).

For backward compatibility the filesystem cache still remains a list.

On this test:

    import pytest
    @pytest.mark.parametrize("x", range(5000))
    def test_foo(x): pass

run with `pytest --collect-only`:

Before: 0m1.251s
After:  0m0.921s
2020-04-29 13:02:38 +03:00
Ran Benita 49e50d3106 testing: fix warning issued by test_cache_writefail_cachfile_silent
Remove this message which was shown in the warning summary of pytest's
own testsuite:

    testing/test_cacheprovider.py::TestNewAPI::test_cache_writefail_cachfile_silent
      testing/test_cacheprovider.py:40: PytestCacheWarning: could not create cache path /tmp/pytest-of-ran/pytest-2/test_cache_writefail_cachfile_silent0/.pytest_cache/v/test/broken
        cache.set("test/broken", [])
2020-04-28 22:49:00 +03:00
Ran Benita 9bf3efb8e9
Merge pull request #7120 from bluetech/update-dev
pre-commit: update some tool revisions
2020-04-25 23:07:15 +03:00
Ran Benita 9828cfa339
Merge pull request #7117 from bluetech/deprecate-fillfuncargs-v2
fixtures: deprecate pytest._fillfuncargs function
2020-04-24 22:59:06 +03:00
Ran Benita 3cd97d50f9 pre-commit: update pyupgrade 1.18.0 -> 2.2.1 2020-04-24 21:57:38 +03:00
Ran Benita e269407e65 testing: avoid pytest_collect_directory message in warnings summary
Currently this test issues a warning which is displayed in the warning
summary (of pytest's own test suite):

  testing/acceptance_test.py::TestGeneralUsage::test_early_skip
    /tmp/pytest-of-ran/pytest-396/test_early_skip0/conftest.py:2: PytestDeprecationWarning: The pytest_collect_directory hook is not working.
    Please use collect_ignore in conftests or pytest_collection_modifyitems.
      def pytest_collect_directory():

I think the filter was meant to be `ignore` in the first place, and not
`always` which is not a valid action AFAIK.
2020-04-24 19:06:31 +03:00
Ran Benita 907e29a47b fixtures: deprecate pytest._fillfuncargs function
This function is exposed and kept alive for the oejskit plugin which is
abandoned and no longer works with recent plugins, so let's prepare to
completely remove it.
2020-04-24 18:54:46 +03:00
Katarzyna Król 7789b51acb
Issue 4677 - always relative path in skip report (#6953) 2020-04-17 08:28:36 +03:00
Simon K de6c28ed1f
Improve error handling around yieldctx fixtures which do not yield a value (#7083) 2020-04-15 12:17:13 +03:00
symonk 251e8f212e refactor mark tests, widen catching and make error msg more concise 2020-04-13 14:25:01 +01:00
symonk 87edc09dea Gracefully handle eval() failure(s) for marker expressions 2020-04-13 13:25:06 +01:00
Ronny Pfannschmidt 244c8e4a13
Merge pull request #6680 from RonnyPfannschmidt/fix-6294-more-docs-for-fromparent
doc: more docs for from_parent
2020-04-10 13:10:40 +02:00
Ran Benita df66a953a1
Merge pull request #7048 from bluetech/fix-test_assertrewrite-reprcompare
Remove broken _reprcompare disabling fixture in test_assertrewrite.py
2020-04-10 12:51:11 +03:00
Ran Benita 9ffccf5acc
Merge pull request #7055 from bluetech/rm-test_juintxml-unichr
Remove Python 2 compat code in test_juintxml.py
2020-04-10 11:52:45 +03:00
Ran Benita f0d1ccd32f
Merge pull request #7056 from bluetech/rm-test_monkeypatch-oldstyleclass
Remove Python 2 compat check in test_monkeypatch.py
2020-04-10 11:52:01 +03:00
Ran Benita 41d1ecf521
Merge pull request #7057 from bluetech/skip-faulthandler-test_timeout
Skip flaky test test_faulthandler.py::test_timeout[True]
2020-04-10 11:51:31 +03:00
Ronny Pfannschmidt 19c243f0fa
Merge pull request #6285 from earonesty/patch-1
Add _pytest.fixtures.FixtureLookupError to top level import
2020-04-10 07:58:58 +02:00
Daniel Hahler 0b5d2ff526 Fix/improve printing of docs for collected items 2020-04-09 21:49:30 +02:00
Daniel Hahler f136b79f1a
Fix test_no_warnings to handle e.g. `_pytest.async` (#7044)
Before this patch it would result in a SyntaxError with e.g. `import _pytest.async`.
2020-04-09 16:56:01 +02:00
Ran Benita 2aa5436ee7 Remove Python 2 compat code in test_juintxml.py 2020-04-09 17:33:55 +03:00
Ran Benita 5a5fd01ebe Skip flaky test test_faulthandler.py::test_timeout[True]
It occasionally crashes on CI, the reason seems out of our control, or
at least we can't figure it out.
2020-04-09 17:23:54 +03:00
Ran Benita 08b3d37177 Remove Python 2 compat check in test_monkeypatch.py
Presumably it used to test old-style vs. new-style classes, but in
the Python 3 conversion SampleNew and SampleOld became the same.
2020-04-09 17:11:18 +03:00
Ran Benita 8fab3dd42f Remove broken _reprcompare disabling fixture in test_assertrewrite.py
The `_pytest._code._reprcompare` that was referred to previously doesn't
exist -- it was moved to other places but wasn't updated. This regressed
in f423ce9c01. Now we don't want it
anymore, so keep the status quo by explicitly removing them.
2020-04-09 10:47:45 +03:00
Ran Benita 20956b2f4e Remove some no-longer-needed compat code in test_assertion 2020-04-08 21:35:42 +03:00
Daniel Hahler e6da086101
Update testing/test_pytester.py
Co-Authored-By: Ran Benita <ran@unusedvar.com>
2020-04-08 18:16:03 +02:00
Daniel Hahler 7048d5be9c
Fix FD leak in test__get_multicapture (#7037)
Instantiating `FDCapture` creates a file descriptor already.  Use "no"
to not leak a fd here.
2020-04-08 18:11:31 +02:00
Daniel Hahler 4fd2623c12
tests: fix TypeErrors (#7038)
* tests: fix TypeError with test_mark_closest

It fails when trying to run it actually:

> TypeError: test_has_inherited() takes 0 positional arguments but 1 was given

* Fix testing/test_collection.py::TestCollector::test_getparent
2020-04-08 18:11:04 +02:00
Ran Benita eab0a6e34d Revert "Increase test_faulthandler.py::test_timeout sleep duration on CI" 2020-04-07 13:20:35 +03:00
Ran Benita 259e5d0610
Merge pull request #7034 from bluetech/fix-testdurations-flaky
Fix flaky TestDurations test
2020-04-07 09:39:02 +03:00
Daniel Hahler bf3e64d473
Remove TestExecutionForked - xdist.boxed has gone since long (#7021)
Tried to write a test using `--boxed`, but it fails due to
https://github.com/pytest-dev/pytest-forked/issues/30.
2020-04-07 08:07:20 +02:00
Ran Benita c3e6e2e8c8 Fix flaky TestDurations test
TestDurations tests the `--durations=N` functionality which reports N
slowest tests, with durations <= 0.005s not shown by default.

The test relies on real time.sleep() (in addition to the code which uses
time.perf_counter()) which makes it flaky and inconsistent between
platforms.

Instead of trying to tweak it more, make it use fake time instead. The
way it is done is a little hacky but seems to work.
2020-04-06 23:49:46 +03:00
Ran Benita 7da3e3aaad Increase test_faulthandler.py::test_timeout sleep duration on CI
This might help fix some flakiness.
2020-04-06 11:55:03 +03:00
Daniel Hahler fc645412aa Fix `test_popen_default_stdin_stderr_and_stdin_None` when run with `-s` 2020-04-06 08:32:41 +02:00
Ran Benita 1ce30fd38f Document the pytest_report_teststatus hook better and test uncovered functionality
This hook has some functionality to provide explicit markup for the test
status. It seemed unused and wasn't tested, so I was tempted to remove
it, but I found that the pytest-rerunfailures plugin uses it, so
document it and add a test instead.
2020-04-04 17:27:59 +03:00
Daniel Hahler e01dcbf323
Cleanup/move imports with tmpdir tests (#7015) 2020-04-04 14:25:34 +02:00
Daniel Hahler 48c9f556ef
Fix tests: use explicit syspathinsert where tests might hang (#7008)
Use `testdir.syspathinsert()` with multiprocessing tests:

- test_chained_exceptions_no_reprcrash
- test_exception_handling_no_traceback

This only works currently because `_importtestmodule` changes `sys.path`
as a side-effect.

It appears to be only required on Windows though - likely due to the
multiprocessing method used there.
2020-04-04 12:33:15 +02:00
Daniel Hahler 20f6331afd
Fix TerminalRepr instances to be hashable (#6988)
pytest-xdist assumes `ExceptionChainRepr` is hashable.

Fixes https://github.com/pytest-dev/pytest/issues/6925.
Fixes https://github.com/pytest-dev/pytest-xdist/issues/515.
2020-04-03 00:56:53 +02:00
Ran Benita 03451c397f Simplify positional arguments compatibility code in pytest.fixture()
The dynamic scope feature added in 10bf6aac76
necessitated some wrangling of arguments in pytest.fixture(). In
particular, it deprecated positional arguments in favor of keyword-only
arguments, while keeping backward compatibility.

The way it did this avoided some code duplication but ended up being
quite hard to follow and to annotate with types.

Replace it with some straightforward code, which is not very DRY but is
simple and easy to remove when the time comes.
2020-04-02 14:52:58 +03:00
Daniel Hahler ff0a091165 Fix/improve test_terminal_reporter_writer_attr
It did not actually test that the attribute gets set.
This also checks the stacklevel etc.
2020-03-31 09:31:38 +02:00
Ronny Pfannschmidt 2d9dac95ec
Merge pull request #6927 from RonnyPfannschmidt/fix-6924-run-async-stdlib-unittests
running stdlib asyncio unittests again
2020-03-30 22:34:17 +02:00
Ronny Pfannschmidt 451aef65ac prepare tests and disable warnings for asyncio unittest cases
shoehorn unittest async results into python test result interpretation

changelog
2020-03-30 21:55:12 +02:00
Ronny Pfannschmidt f1d51ba1f5 deprecate the pytest.collect module
changelog

minimal unittest for collect module deprecations

\!fixup - changelog typo
2020-03-30 21:53:07 +02:00
Ronny Pfannschmidt eab2831671 fix #6951: allow to write TerminalReporter.writer 2020-03-30 21:31:53 +02:00
smarie 95fadd5740
Improved time counter used to compute test durations. (#6939)
Co-authored-by: Sylvain MARIE <sylvain.marie@se.com>
Co-authored-by: Ran Benita <ran@unusedvar.com>
Co-authored-by: Bruno Oliveira <nicoddemus@gmail.com>
2020-03-29 15:20:09 +03:00
Ran Benita a785754523 Change EnvironmentError, IOError to OSError - they are aliases
Since Python 3.3, these are aliases for OSError:
https://docs.python.org/3/whatsnew/3.3.html#pep-3151-reworking-the-os-and-io-exception-hierarchy
2020-03-27 18:40:23 +03:00
Bruno Oliveira a016a75ca7 Fix linting 2020-03-27 09:54:20 -03:00
Bruno Oliveira 429a28eca0
Merge pull request #6782 from nicoddemus/code-highlight-followup
Assorted improvements following up #6658
2020-03-27 08:58:50 -03:00
Daniel Hahler e651562271
test_warnings: clean up usage of pyfile_with_warnings (#6799)
Remove it where not used / overwritten, and use its reference otherwise,
which makes it clear that it is used actually.
2020-03-27 02:24:00 +01:00
Daniel Hahler 1fda861190 Fix crash when printing while capsysbinary is active
Previously, writing to sys.stdout/stderr in text-mode (e.g.
`print('foo')`) while a `capsysbinary` fixture is active, would crash
with:

    /usr/lib/python3.7/contextlib.py:119: in __exit__
        next(self.gen)
    E   TypeError: write() argument must be str, not bytes

This is due to some confusion in the types. The relevant functions are
`snap()` and `writeorg()`. The function `snap()` returns what was
captured, and the return type should be `bytes` for the binary captures
and `str` for the regular ones. The `snap()` return value is eventually
passed to `writeorg()` to be written to the original file, so it's input
type should correspond to `snap()`. But this was incorrect for
`SysCaptureBinary`, which handled it like `str`.

To fix this, be explicit in the `snap()` and `writeorg()`
implementations, also of the other Capture types.

We can't add type annotations yet, because the current inheritance
scheme breaks Liskov Substitution and mypy would complain. To be
refactored later.

Fixes: https://github.com/pytest-dev/pytest/issues/6871
Co-authored-by: Ran Benita (some modifications & commit message)
2020-03-16 18:21:33 +02:00
Ran Benita 29e4cb5d45 Remove safe_text_dupfile() and simplify EncodedFile
I tried to understand what the `safe_text_dupfile()` function and
`EncodedFile` class do. Outside tests, `EncodedFile` is only used by
`safe_text_dupfile`, and `safe_text_dupfile` is only used by
`FDCaptureBinary.__init__()`. I then started to eliminate always-true
conditions based on the single call site, and in the end nothing was
left except of a couple workarounds that are still needed.
2020-03-14 12:57:08 +02:00
Bruno Oliveira 010e711971 Merge pull request #6914 from nicoddemus/revert-6330
Revert "[parametrize] enforce explicit argnames declaration (#6330)"
2020-03-13 10:49:48 -03:00
Bruno Oliveira 2eedf9c2aa
Merge pull request #6910 from nicoddemus/resultlog-logreport
Handle unknown stats in pytest_report_teststatus hook
2020-03-13 09:30:04 -03:00
Bruno Oliveira 0c58ed2cc0 Handle unknown stats in pytest_report_teststatus hook
Noticed that the pytest_report_teststatus of reportlog was not properly
handling unknown statuses while taking a look at:

https://github.com/pytest-dev/pytest-rerunfailures/issues/103
2020-03-12 20:52:22 -03:00
Ran Benita 6954b3b0dc Assume os.dup is always available
The commit which added the checks for os.dup a15afb5e48
suggests it was done for Jython. But pytest doesn't support Jython
anymore (Jython is Python 2 only).

Furthermore, it looks like the faulthandler plugin (bundled in pytest
and enabled by default) uses os.dup() unprotected and there have not
been any complaints.

So seems better to just remove these checks, and only add if someone
with a legitimate use case complains.
2020-03-12 16:47:15 +02:00
Daniel Hahler db92cea14c
black: --target-version py35 (#6872) 2020-03-08 01:24:31 +01:00
Daniel Hahler bce1d40fb0
tests: harden test_reprcompare_notin, factor out callop (#6764)
* tests: assertion: factor out `callop`, typing

* tests: harden test_reprcompare_notin
2020-03-08 01:23:19 +01:00
Daniel Hahler dc86fb6758 pre-commit run --all-files 2020-03-07 23:47:55 +01:00
Ran Benita b1d7a187f2 Add setdefault() method to Store
Can be useful in some cases.
2020-03-06 11:42:20 +02:00
Daniel Hahler acec0b688f
Fix usage of pytester with doctests (#6802)
Use `request.node.name` instead of `request.function.__name__`:
`request.function` is `None` with `DoctestItem`s.
2020-03-04 05:33:50 +01:00
Ronny Pfannschmidt 9fd71d6fe0
fix #571: deprecate pytest_collect_directory as ... (#6847)
Deprecate pytest_collect_directory

Fix #571

Co-authored-by: Daniel Hahler <github@thequod.de>
2020-03-03 18:58:14 -03:00
earonesty 7667ff51e7 Update fixtures.py 2020-03-03 09:59:38 -03:00
earonesty 74cdff86f8 Update conftest.py 2020-03-03 09:59:38 -03:00
Ronny Pfannschmidt 3d390940d1 refer the node-from-parent deprecation documentation in the warning
fixup: fix test for warning
2020-03-01 20:33:46 +01:00
Ronny Pfannschmidt 194b52145b
Merge pull request #6834 from RonnyPfannschmidt/fix-6833-summarize-warning-item-locations
summarize warning summaries if the number of locations is high
2020-03-01 20:21:36 +01:00
Ronny Pfannschmidt 23c43a37e0 summarize warning summaries if the number of locations is high 2020-03-01 14:08:15 +01:00
Bruno Oliveira 92767fec51
Merge pull request #6836 from bluetech/store
Add a typing-compatible mechanism for ad-hoc attributes on various objects
2020-03-01 09:30:10 -03:00
Bruno Oliveira ff7b5dbbde
Merge pull request #6784 from nicoddemus/deprecate-terminal-writer
Deprecate TerminalReporter.writer
2020-02-28 21:07:02 -03:00
Daniel Hahler 8128f4b3b8 Fix test_write_pyc: passed list to parseconfig 2020-02-28 20:40:39 +01:00
Daniel Hahler 6c236767e0 Adjust/fix test_config: use strs with determine_setup 2020-02-28 20:40:39 +01:00
Daniel Hahler 5819536f00
Improve UsageError with invalid `-o` style (#6795)
This started from fixing the test, where `"xdist_strict True"` was used
as a single argument, although you typically would see `["xdist_strict",
"True"]`.

Improves the error message to mention the option that caused the error.
2020-02-28 19:41:56 +01:00
Daniel Hahler 952cab2d85
Simplify test_rootdir_wrong_option_arg (#6812) 2020-02-28 18:38:07 +01:00
Ran Benita d636fcd557 Add a typing-compatible mechanism for ad-hoc attributes on various objects
pytest has several instances where plugins set their own attributes on
objects they receive in hooks, like nodes and config. Since plugins are
detached from these object's definition by design, this causes a problem
for type checking because these attributes are not defined and mypy
complains.

Fix this by giving these objects a "store" which can be used by plugins
in a type-safe manner.

Currently this mechanism is private. We can consider exposing it at a
later point.
2020-02-28 14:34:44 +02:00
Daniel Hahler 6a7df7f031
test_assertion: harden/improve test_{text_diff,unicode} (#6806) 2020-02-24 15:19:08 +01:00
Daniel Hahler ac3a42bafd
doctest: strip newlines with unexpected exceptions (#6801) 2020-02-24 15:18:08 +01:00
Daniel Hahler bfd0d18371
tests: test_config: move tests (#6796)
Originally added in a2891420d (with `TestRootdir`), but then
accidentally moved to `TestOverrideIniArgs` in 802755cee.
2020-02-23 17:12:55 +01:00
Daniel Hahler 706ea86bba
capture: factor out _get_multicapture (#6788)
Ref: https://github.com/pytest-dev/pytest/pull/6671#issuecomment-588408992
2020-02-22 23:39:20 +01:00
Daniel Hahler c8b4a1a471
Handle `match` with `pytest.raises()` (#6753)
Fixes https://github.com/pytest-dev/pytest/issues/6752.
2020-02-22 23:32:55 +01:00
Daniel Hahler 077001fe5c tests: simplify test_pytest_plugins_in_non_top_level_conftest_unsupported_no_false_positives 2020-02-22 23:31:37 +01:00
Daniel Hahler 68fe0eb8f3
Minor cosmetic fixes (#6792) 2020-02-22 19:24:41 +01:00
Daniel Hahler 478a244f5e
main: `args` must be a list, not tuple (#6791)
Passing in a tuple crashes in `_prepareconfig`:

        def test_invoke_with_tuple(self):
    >       pytest.main(("-h",))

    src/_pytest/config/__init__.py:82: in main
        config = _prepareconfig(args, plugins)
    src/_pytest/config/__init__.py:229: in _prepareconfig
        return pluginmanager.hook.pytest_cmdline_parse(
    …
    src/_pytest/helpconfig.py:98: in pytest_cmdline_parse
        config = outcome.get_result()  # type: Config
    src/_pytest/config/__init__.py:808: in pytest_cmdline_parse
        self.parse(args)
    src/_pytest/config/__init__.py:1017: in parse
        self._preparse(args, addopts=addopts)
    _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

        def _preparse(self, args: List[str], addopts: bool = True) -> None:
            …
            if addopts:
                ini_addopts = self.getini("addopts")
                if ini_addopts:
    >               args[:] = self._validate_args(ini_addopts, "via addopts config") + args
    E               TypeError: can only concatenate list (not "tuple") to list

    addopts    = True
    args       = ('-h',)
    env_addopts = ''
    ini_addopts = ['-rfEX', …]

    src/_pytest/config/__init__.py:956: TypeError: can only concatenate list (not "tuple") to list

Might be worth handling (converting it to a list for example), but it
was documented to be a list to begin with when removing support for
strings (a7e401656).
2020-02-22 13:16:46 +01:00
Daniel Hahler 1baeefc2fd test_reprcompare_whitespaces: use callequal 2020-02-22 13:15:17 +01:00
Daniel Hahler 2be06ba67e
Improve doc/typing/message for `ExceptionInfo.match` (#6776) 2020-02-21 16:41:57 +01:00
Daniel Hahler 8e991a622c
tests: harden/improve test_itemreport_subclasses_show_subclassed_file (#6467)
* tests: harden test_itemreport_subclasses_show_subclassed_file

* extend test_itemreport_subclasses_show_subclassed_file
2020-02-21 15:24:12 +01:00
Daniel Hahler b099fcfa33
tests: runner: improve/ignore coverage (#6781) 2020-02-21 14:37:56 +01:00
Daniel Hahler 81a9df6ed1
tests: fix flaky test_timeout (#6773)
Use a longer timeout on CI - seen a failure with it with GHA (Windows).

Ref: a4554e666a
2020-02-21 12:52:31 +01:00
Bruno Oliveira 435ad221f9 Deprecate TerminalReporter.writer
Fix #6779
2020-02-20 21:04:49 -03:00
Bruno Oliveira c91abe48ba Assorted improvements following up #6658 2020-02-20 18:51:41 -03:00
Daniel Hahler d1b50526fa
tests: harden some UsageError tests (matching the error msg) (#6775) 2020-02-20 13:29:59 +01:00
Daniel Hahler fb16d3e27a
capture: revisit/fix __repr__, define _in_suspended (#6749) 2020-02-20 00:51:57 +01:00
Daniel Hahler 2b13a9b95d
Use TYPE_CHECKING (#6771) 2020-02-19 22:07:54 +01:00
Daniel Hahler 1b30514783
LFPlugin: use sub-plugins to deselect during collection (#6448)
Fixes https://github.com/pytest-dev/pytest/issues/5301.

Refactor/steps:

- use var
- harden test_lastfailed_usecase
- harden test_failedfirst_order
- revisit last_failed_paths
- harden test_lastfailed_with_known_failures_not_being_selected
2020-02-19 21:33:03 +01:00
Ran Benita af2b0e1174
Merge pull request #6758 from bluetech/outcome-exception-callable-2
Use a hack to make typing of pytest.fail.Exception & co work
2020-02-19 22:08:21 +02:00
Daniel Hahler f95c7f5803
doctest: handle any OutcomeException (#6669)
Fixes using `pytest.xfail()` and `pytest.importorskip()` in doctests.

Ref: https://github.com/pytest-dev/pytest/issues/310
2020-02-19 13:16:37 +01:00
Ran Benita 24dcc76495 Use a hack to make typing of pytest.fail.Exception & co work
Mypy currently is unable to handle assigning attributes on function:
https://github.com/python/mypy/issues/2087.
pytest uses this for the outcome exceptions -- `pytest.fail.Exception`,
`pytest.exit.Exception` etc, and this is the canonical name by which they
are referred.

Initially we started working around this with type: ignores, and later
by switching e.g. `pytest.fail.Exception` with the direct exception
`Failed`. But this causes a lot of churn and is not as nice. And I also
found that some code relies on it, in skipping.py:

    def pytest_configure(config):
        if config.option.runxfail:
            # yay a hack
            import pytest

            old = pytest.xfail
            config._cleanup.append(lambda: setattr(pytest, "xfail", old))

            def nop(*args, **kwargs):
                pass

            nop.Exception = xfail.Exception
            setattr(pytest, "xfail", nop)
        ...

So it seems better to support it. Use a hack to make it work. The rest
of the commit rolls back all of the workarounds we added up to now.

`pytest.raises.Exception` also exists, but it's not used much so I kept
it as-is for now.

Hopefully in the future mypy supports this and this ugliness can be
removed.
2020-02-18 23:17:27 +02:00
Daniel Hahler 442f7a7706
Do not use fixed line number with test_cache_failure_warns (#6748)
It was not previously checking for the line number also (02aa8ad), and this is
obviously wrong (affected by changes to the file).
2020-02-18 09:27:33 +01:00
Ran Benita 7b8968ff80
Merge pull request #6735 from bluetech/metafunc-annotate
Type annotate Metafunc
2020-02-15 23:32:14 +02:00
Daniel Hahler e872532d0c Merge branch 'master' into term-color
Conflicts:
	src/_pytest/terminal.py
	testing/test_debugging.py
	testing/test_terminal.py
2020-02-15 18:46:29 +01:00
Ran Benita 5945c3fe88 Type annotate Metafunc 2020-02-15 17:13:18 +02:00
Daniel Hahler 2b5adc88a7 Move test_issue4445_cacheprovider_set into test_cache_failure_warns
Would need to be adjusted anyway non-trivially, and we can just harden
`test_cache_failure_warns` instead.
2020-02-15 02:01:22 +01:00
Daniel Hahler 02aa8adae1 cacheprovider: use warnings directly
Allows for filtering of PytestCacheWarning.

Using `_issue_warning_captured` is not necessary here, and was probably
only used because the cacheprovider misses warnings during
`pytest_sessionfinish`, which is also fixed here.

I think the usage of `_issue_warning_captured` can be removed/reduced
further, but also that this is good enough for now.

Ref: https://github.com/pytest-dev/pytest/issues/6681.
2020-02-15 01:36:57 +01:00
Daniel Hahler 67e69a7e49
tests: harden test_xdist_verbose (#6700) 2020-02-15 01:22:01 +01:00
Daniel Hahler 4b70ba2c21
tests: harden test_better_reporting_on_conftest_load_failure (#6713) 2020-02-14 17:00:01 +01:00
Daniel Hahler de3353aac1
test_load_initial_conftest_last_ordering: handle testing package (#6706) 2020-02-14 16:58:17 +01:00
Daniel Hahler d89b5057ca
assertrepr_compare: provide more info (location) with exceptions (#6728) 2020-02-14 02:17:05 +01:00
Daniel Hahler 83137c89e9
tests: test_unicode_plus_minus: use unicode sign directly (#6727)
Was globbed for Python 2 before (57c448991).
2020-02-14 02:16:25 +01:00