Compare commits

...

1819 Commits
3.7.0 ... 4.4.2

Author SHA1 Message Date
Bruno Oliveira
3ac43314ee Preparing release version 4.4.2 2019-05-08 12:46:14 -03:00
Bruno Oliveira
972410f8b6 Require pluggy>=0.11 (#5229)
Require pluggy>=0.11
2019-05-08 12:40:49 -03:00
Romain Chossart
0cf267f187 Add changelog entry for #5229 2019-05-08 16:13:28 +01:00
Sitaktif
7161f5b372 Require pluggy>=0.11
Pluggy 0.10.0 introduced a new dependency `importlib-metadata` but that
package cannot be imported when installed as an egg and that is causing
problems for users relying on `setup.py` to install packages present in
`test_require`. This change was quickly reverted in pluggy 0.11.0.

See https://github.com/pytest-dev/pluggy/issues/205
2019-05-08 16:06:41 +01:00
Bruno Oliveira
1d466d0aa7 Use exec directly (#5224)
Use exec directly
2019-05-07 10:02:12 -03:00
Bruno Oliveira
ef4dec0bcf Skip test_source_mtime_long_long on 32bit and lower platforms (#5045)
Skip test_source_mtime_long_long on 32bit and lower platforms
2019-05-07 09:42:18 -03:00
Bruno Oliveira
d76735f9e5 Restore usedevelop=True now that pip 19.1.1 restored the old behavior (#5222)
Restore usedevelop=True now that pip 19.1.1 restored the old behavior
2019-05-07 08:46:47 -03:00
Anthony Sottile
d1a48ad68f Use exec directly 2019-05-06 23:07:39 -07:00
Bruno Oliveira
6d259c400e Merge pull request #5223 from 5uper5hoot/patch-1
Clarify docs for pytest.raises `match`.
2019-05-06 21:57:47 -03:00
Bruno Oliveira
d3686361ba Fix linting 2019-05-07 00:52:40 +00:00
Peter Schutt
8605ed2a15 Update python_api.py 2019-05-07 10:10:25 +10:00
Peter Schutt
8b34d981fc Clarify docs for pytest.raises match.
For #5208.

Document explicit behavior of `match` and brief note on how to handle matching a string that may contain special re chars.
2019-05-07 09:56:13 +10:00
Bruno Oliveira
2795689435 Restore usedevelop=True now that pip 19.1.1 restored the old behavior
Fix #5167
2019-05-06 19:42:06 -03:00
Bruno Oliveira
dcf65a9643 Add links to pytest.raises message workaround (#5218)
Add links to pytest.raises `message` workaround
2019-05-06 18:56:40 -03:00
Bruno Oliveira
784e1e3b7e Add links to pytest.raises message workaround
Related to #3974
2019-05-06 12:35:27 -03:00
Daniel Hahler
b25802eca7 Merge pull request #5212 from jdufresne/new-black
Update Black URLs
2019-05-05 07:58:27 +02:00
Daniel Hahler
7f7f84757d Merge pull request #5211 from hugovk/upgrade-pypy
Upgrade PyPy to 7.1.1
2019-05-05 04:50:11 +02:00
Jon Dufresne
143499d041 Update Black URLs
> Black, your uncompromising #Python code formatter, was a project
> created with the community in mind from Day 1. Today we moved it under
> the PSF umbrella. It's now available on GitHub under
> https://github.com/python/black/ . You install and use it just like
> before.

https://twitter.com/llanga/status/1123980466292445190
2019-05-04 08:28:50 -07:00
Hugo
26b41a5914 Upgrade PyPy to 7.1.1 2019-05-04 17:54:57 +03:00
Bruno Oliveira
e1a426c067 Unify pypy (#5209)
Unify pypy
2019-05-04 10:46:14 -03:00
Bruno Oliveira
2bd97ebaf7 Use 'pypy' as executable on PyPy env [skip travis] 2019-05-04 10:27:06 -03:00
Bruno Oliveira
45eeb53c98 Fix a typo (#5207)
Fix a typo
2019-05-04 10:04:50 -03:00
Don Kirkby
254b195f50 Fix a typo 2019-05-03 22:30:20 -07:00
Bruno Oliveira
1c13418a8b doc: fix hooks 'path' parameter doc type (#5198)
doc: fix hooks 'path' parameter doc type
2019-05-02 21:05:07 -03:00
DamianSkrzypczak
299e6479c1 add DamianSkrzypczak to AUTHORS 2019-05-02 23:45:34 +02:00
DamianSkrzypczak
6e81c3df92 add changelog for issue #5171 fixes 2019-05-02 21:30:03 +02:00
DamianSkrzypczak
1bd7d287a7 doc: fix hooks 'path' parameter doc type
by changing it from str to py.path.local
(#5171)
2019-05-02 20:51:11 +02:00
Anthony Sottile
b82e1b87cc Merge pull request #5195 from nicoddemus/pytest-config-docs
Add quick note about accessing config through session or item objects
2019-05-02 09:52:42 -07:00
Bruno Oliveira
af40473c9a Add quick note about accessing config through session or item objects
Fix #5030
2019-05-01 11:46:35 -03:00
Bruno Oliveira
f17b734989 Improve help for --runxfail flag (#5188)
Improve help for --runxfail flag
2019-05-01 11:00:31 -03:00
Allan Lewis
f050203f5d Improve help for --runxfail flag
The help for the '--runxfail' flag is somewhat misleading. The default
behaviour is to run tests marked as 'xfail' but to ignore the results. This
flag alters that behaviour by running these tests as if they weren't marked
'xfail', i.e. their results are not ignored.
2019-05-01 10:04:32 +01:00
Matt Cooper
bc6450773a remove PyPy special casing 2019-04-29 08:39:48 -04:00
Bruno Oliveira
204004c8b8 Review doctest docs (#5183)
Review doctest docs
2019-04-29 08:02:59 -03:00
Bruno Oliveira
772a4a5cf3 Remove all version references to obsolete pytest versions (#5184)
Remove all version references to obsolete pytest versions
2019-04-29 08:02:32 -03:00
Bruno Oliveira
d9cad1e759 Merge pull request #5176 from nicoddemus/initial-conftests-note
Add note about pytest_load_initial_conftests working only from plugins
2019-04-29 07:59:27 -03:00
Anthony Sottile
6fb3baf071 Merge pull request #5182 from nicoddemus/removed-unused-deprecation-msgs
Removed unused warning message
2019-04-28 20:26:11 -07:00
Bruno Oliveira
e943aff995 Update blurb about Sybil 2019-04-28 20:01:22 -03:00
Bruno Oliveira
9c5da9c0d1 Remove all version references to obsolete pytest versions
Remove version references to pytest 2 and 3.

Just like Python 3 no longer has references to Python 2, I think
we should follow the same approach in pytest.
2019-04-28 12:37:58 -03:00
Bruno Oliveira
f6ab6d71ad Run regendoc 2019-04-28 12:17:15 -03:00
Bruno Oliveira
67755d67fb Review doctest docs
* Add pytest.skip() example
* Add blurb about Sybil
* Create a subsection for doctest-options
* Create a subsection for pytest-specific features
2019-04-28 12:17:15 -03:00
Bruno Oliveira
a3c2ec3c5b Add CHANGELOG for #5182 2019-04-28 11:10:21 -03:00
Bruno Oliveira
9742f11d37 Removed unused warning message 2019-04-28 11:06:47 -03:00
Bruno Oliveira
50937fe622 Add note about pytest_load_initial_conftests working only from plugins
Fix #5175
2019-04-27 10:12:27 -03:00
Bruno Oliveira
9c700d1fd5 Workaround for editable installs with pip 19.1 (#5168)
Workaround for editable installs with pip 19.1
2019-04-26 18:29:28 -03:00
Bruno Oliveira
19cd4d0af7 Workaround for editable installs with pip 19.1
Related to #5167
2019-04-25 19:40:01 -03:00
Bruno Oliveira
bf0fe1a1fa GitHub: revisit issue/PR templates [ci skip] (#5158)
GitHub: revisit issue/PR templates  [ci skip]
2019-04-24 12:09:55 -03:00
Daniel Hahler
3df32e2732 GitHub: revisit issue/PR templates [ci skip]
The motivation here is to not have the same boilerplate with PRs.
2019-04-23 18:01:13 +02:00
Daniel Hahler
34bc594beb Merge pull request #5133 from kondratyev-nv/fix-handle-repr-error-with-showlocals
Fix handle repr error with showlocals and verbose output
2019-04-19 19:23:39 +02:00
Nikolay Kondratyev
bc00d0f7db Fix handle repr error with showlocals and verbose output 2019-04-19 18:54:21 +03:00
Daniel Hahler
e87d3d70e2 Merge pull request #5138 from ikonst/notify_exception_without_terminal
Fix dependencies on 'terminal' plugin
2019-04-17 23:20:49 +02:00
Ilya Konstantinov
d67d68f6d3 Eliminate core dependency on 'terminal' plugin 2019-04-17 11:19:19 -07:00
Bruno Oliveira
008d04398a Merge pull request #5135 from dougthor42/patch-1
[Docs] Fix typo in skipping.rst
2019-04-17 14:36:57 -03:00
Douglas Thor
0e651d7297 [Docs] Fix typo in skipping.rst
One of the `pytest.mark.skipif` blocks does not use the `reason` kwarg.
2019-04-16 09:30:13 -07:00
Bruno Oliveira
9eac4733c5 Merge pull request #5129 from nicoddemus/release-4.4.1
Release version 4.4.1
2019-04-15 14:41:36 -03:00
Bruno Oliveira
006dc30476 Preparing release version 4.4.1 2019-04-15 14:24:17 +00:00
Daniel Hahler
533e610a35 Merge pull request #5098 from blueyed/fix-syspath_prepend
monkeypatch.syspath_prepend: invalidate import cache
2019-04-13 18:46:16 +02:00
Daniel Hahler
8fd5a658eb monkeypatch.syspath_prepend: invalidate import cache
This was done with testdir only, and uses the fixed monkeypatch method
there now.
2019-04-13 16:15:44 +02:00
Anthony Sottile
c3b7efc818 Merge pull request #5097 from asottile/unknown_kwargs_param
Produce a warning when unknown arguments are passed to pytest.param()
2019-04-12 13:30:07 -07:00
Anthony Sottile
43e7401c91 Produce a warning when unknown arguments are passed to pytest.param() 2019-04-12 13:00:39 -07:00
Bruno Oliveira
a9e850f749 Merge pull request #5096 from asottile/docs_highlight
blacken-docs more code samples in docs
2019-04-12 10:00:26 -03:00
Anthony Sottile
da2e092163 pre-commit autoupdate 2019-04-12 04:52:47 -07:00
Anthony Sottile
8449294e5d blacken-docs more code samples in docs 2019-04-12 04:50:26 -07:00
Bruno Oliveira
1dafe969d1 Merge pull request #5093 from blueyed/tbreportdemo
docs: tbreportdemo: remove obsolete comment
2019-04-11 13:07:02 -03:00
Daniel Hahler
1f66e3b0d0 docs: tbreportdemo: remove obsolete comment 2019-04-11 11:39:23 +02:00
Bruno Oliveira
bc157417e1 Merge pull request #5051 from blueyed/fix-test
Fix test_conftest when run via pytest-randomly
2019-04-10 19:08:28 -03:00
Daniel Hahler
8011ff5bda Add _sys_snapshot fixture and use it with more tests 2019-04-05 11:55:23 +02:00
Daniel Hahler
899e74aa14 tests: harden test_immediate_initialiation_and_incremental_are_the_same 2019-04-05 11:55:23 +02:00
Daniel Hahler
66f743c45a Fix test_conftest when run via pytest-randomly 2019-04-05 11:55:23 +02:00
Daniel Hahler
13a9d876f7 Merge pull request #5037 from blueyed/regen
docs: revisit/fix regen
2019-04-04 13:36:47 +02:00
Ondřej Súkup
77526f412c Skip test_source_mtime_long_long on 32bit and lower platforms 2019-04-04 13:14:46 +02:00
Bruno Oliveira
973301b675 Merge pull request #5041 from blueyed/fix-pdbcls-regression
pdb: try to import --pdbcls in pytest_configure only
2019-04-03 19:23:43 -03:00
Daniel Hahler
757ada2fd2 pdb: try to import --pdbcls in pytest_configure only
Fixes https://github.com/pytest-dev/pytest/issues/5039.
2019-04-03 22:35:18 +02:00
Daniel Hahler
befc8a3f10 Update via https://github.com/pytest-dev/regendoc/pull/8 2019-04-03 22:08:44 +02:00
Daniel Hahler
5935fbaa7a doc/en/Makefile: stabilize output between regendoc versions 2019-04-03 22:07:33 +02:00
Daniel Hahler
e8eaebe595 tox.ini: regen: clear pytest cache for stable outcome 2019-04-03 19:53:00 +02:00
Daniel Hahler
cec2dd6a7c doc/en/Makefile: allow passing in REGENDOC_FILES
This allows for:

> make -C doc/en regen REGENDOC_FILES=example/parametrize.rst
2019-04-03 19:53:00 +02:00
Daniel Hahler
266bf2c007 doc: make regen: replace trailing spaces already 2019-04-03 17:34:26 +02:00
Bruno Oliveira
46df1d5fcf Merge pull request #5031 from blueyed/pytester-addopts
pytester: use monkeypatch with Testdir
2019-04-03 11:26:49 -03:00
Daniel Hahler
d91527599a pytester: use monkeypatch with Testdir 2019-04-03 15:02:53 +02:00
Bruno Oliveira
49d690d137 Merge pull request #5014 from nicoddemus/release-4.4.0
Release 4.4.0
2019-03-31 18:14:27 -03:00
Daniel Hahler
4621638f07 Update CHANGELOG.rst
Co-Authored-By: nicoddemus <nicoddemus@gmail.com>
2019-03-29 20:29:40 -03:00
Bruno Oliveira
8881b201aa Preparing release version 4.4.0 2019-03-29 20:49:18 +00:00
Bruno Oliveira
278b289f37 Merge pull request #4968 from blueyed/pdb-do_debug-quit
pdb: do not raise outcomes.Exit with quit in debug
2019-03-29 16:22:02 -03:00
Daniel Hahler
e7ade066b6 Merge pull request #5011 from blueyed/merge-master-into-features
Merge master into features
2019-03-29 18:35:13 +01:00
Daniel Hahler
dee520e310 Merge pull request #5008 from blueyed/setup-cfg-tool-pytest
setup.cfg: use existing [tool:pytest] (ignoring [pytest])
2019-03-29 16:47:31 +01:00
Daniel Hahler
4e931b258d Merge master into features 2019-03-29 11:05:46 +01:00
Daniel Hahler
4011021823 pdb: do not raise outcomes.Exit with quit in debug 2019-03-29 11:02:34 +01:00
Daniel Hahler
bfda2a0050 setup.cfg: use existing [tool:pytest] (ignoring [pytest]) 2019-03-29 10:59:27 +01:00
Bruno Oliveira
2812c087ec Merge pull request #5010 from garytyler/docupdate
Update docs for 'pytest_cmdline_parse' hook to note availability limi…
2019-03-28 22:32:50 -03:00
Bruno Oliveira
6b5cddc48a Merge pull request #4951 from blueyed/fix-pdb-capfix
pdb: handle capturing with fixtures only
2019-03-28 20:34:28 -03:00
Gary Tyler
403f556928 Update docs for 'pytest_cmdline_parse' hook to note availability liminations 2019-03-28 19:25:55 -04:00
Bruno Oliveira
d8ef86aadf Merge pull request #4993 from blueyed/stepwise-report
stepwise: report status via pytest_report_collectionfinish
2019-03-28 20:24:18 -03:00
Bruno Oliveira
a9fe1e159a Merge pull request #4965 from nicoddemus/serialization-hooks
Serialization hooks
2019-03-28 20:22:19 -03:00
Bruno Oliveira
65c8e8a09e Rename hooks: to/from_serializable 2019-03-28 13:41:56 -03:00
Daniel Hahler
46d9243eb0 changelog 2019-03-28 11:56:53 +01:00
Daniel Hahler
63a01bdb33 Factor out pytestPDB._is_capturing 2019-03-28 11:49:01 +01:00
Daniel Hahler
d53209956b test_pdb_continue_with_recursive_debug: mock pdb.set_trace 2019-03-28 11:49:01 +01:00
Daniel Hahler
951213ee09 Use new suspend/resume in global_and_fixture_disabled 2019-03-28 11:49:01 +01:00
Daniel Hahler
ae067df941 add test_pdb_continue_with_recursive_debug 2019-03-28 11:49:01 +01:00
Daniel Hahler
40718efacc Fix/revisit do_continue with regard to conditions 2019-03-28 11:49:01 +01:00
Daniel Hahler
d406786a8d pdb: handle capturing with fixtures only 2019-03-28 11:49:01 +01:00
Daniel Hahler
0ac069da13 Merge pull request #5006 from blueyed/capture-clean
tests: ensure cleanup with configs via get_config()
2019-03-28 11:38:30 +01:00
Daniel Hahler
d17ea7a9c0 tests: ensure cleanup with configs via get_config()
Also done in test_pluginmanager, although no resource warnings are
there at least.

Fixes https://github.com/pytest-dev/pytest/issues/4355.
2019-03-28 00:14:13 +01:00
Daniel Hahler
c92021fc4f Merge pull request #5003 from blueyed/off
Fix off-by-one error with lineno in mark collection error
2019-03-28 00:09:53 +01:00
Daniel Hahler
50a5cebba8 Merge pull request #5002 from blueyed/report
skipping: factor out _get_pos, pass only config to _get_report_str
2019-03-27 23:07:11 +01:00
Bruno Oliveira
6c602c2282 Merge pull request #4995 from youknowone/disble_test_id_escaping
add ini option to disable string escape for parametrization
2019-03-27 17:34:35 -03:00
Daniel Hahler
76c70cbf4c Fix off-by-one error with lineno in mark collection error 2019-03-27 17:44:52 +01:00
Bruno Oliveira
3d9e68ecfd Update doc/en/parametrize.rst 2019-03-28 00:07:28 +09:00
Jeong YunWon
8b0b7156d9 Fix glitches of original patch of disable-test-id-escaping 2019-03-28 00:07:28 +09:00
ApaDoctor
cf6e2ceafd add ini option to disable string escape for parametrization 2019-03-28 00:07:28 +09:00
Bruno Oliveira
69a55d334a Merge pull request #5004 from blueyed/doc-pdb
doc: fix note about output capturing with pdb
2019-03-26 20:20:05 -03:00
Bruno Oliveira
241b7433cd Merge pull request #4978 from blueyed/exit-from-from_assertrepr_compare
Do not swallow outcomes.Exit in assertrepr_compare
2019-03-26 18:39:13 -03:00
Bruno Oliveira
057c97812b Merge pull request #4975 from blueyed/verbose-fixes
Fix usages of "verbose" option
2019-03-26 18:38:39 -03:00
Bruno Oliveira
02188e399d Merge pull request #4987 from blueyed/collect-tbstyle-repr_failure
CollectError.repr_failure: honor explicit tbstyle option
2019-03-26 18:37:49 -03:00
Bruno Oliveira
aae02863db Merge pull request #4999 from nicoddemus/cmdline_parse-early
Docs: modules implementing pytest_cmdline_parse can be early-loaded
2019-03-26 18:14:31 -03:00
Daniel Hahler
49f36bb028 Merge pull request #4988 from blueyed/logging-close
logging: close log_file_handler
2019-03-26 19:57:57 +01:00
Daniel Hahler
52730f6330 doc: fix note about output capturing with pdb
[skip travis]
2019-03-26 18:33:00 +01:00
Daniel Hahler
538efef1ba logging: close log_file_handler
While it should be closed in logging's shutdown [1], the following would
still issue a ResourceWarning:

```
import logging

log_file_handler = logging.FileHandler("temp.log", mode="w", encoding="UTF-8")

root_logger = logging.getLogger()
root_logger.addHandler(log_file_handler)
root_logger.removeHandler(log_file_handler)
root_logger.error("error")

del log_file_handler
```

It looks like the weakref might get lost for some reason.

See https://github.com/pytest-dev/pytest/pull/4981/commits/92ffe42b45 / #4981
for more information.

1: c1419578a1/Lib/logging/__init__.py (L2107-L2139)
2019-03-26 18:24:19 +01:00
Bruno Oliveira
9311d822c7 Fix assertion in pytest_report_unserialize 2019-03-26 12:47:31 -03:00
Daniel Hahler
351529cb50 skipping: factor out _get_pos, pass only config to _get_report_str 2019-03-26 16:29:16 +01:00
Daniel Hahler
94a2e3dddc stepwise: report status via pytest_report_collectionfinish 2019-03-26 13:20:33 +01:00
Bruno Oliveira
ee96214a8d Merge pull request #5000 from blueyed/merge-master-into-features
Merge master into features
2019-03-26 09:01:46 -03:00
Daniel Hahler
e1ae469504 Merge master into features 2019-03-26 10:23:21 +01:00
Daniel Hahler
0d00be4f4f Do not swallow outcomes.Exit in assertrepr_compare 2019-03-26 10:20:00 +01:00
Daniel Hahler
23146e7527 Fix usages of "verbose" option
With `-qq` `bool(config.getoption("verbose"))` is True; it needs to be
checked for `> 0`.
2019-03-26 10:11:25 +01:00
Daniel Hahler
b18df936ea changelog 2019-03-26 10:06:53 +01:00
Daniel Hahler
4148663706 Merge pull request #4979 from blueyed/minor
Minor: whitespace, typo, docs
2019-03-26 10:01:13 +01:00
Bruno Oliveira
3e1971eb16 Merge pull request #4994 from blueyed/test_as_errors-subprocess
test_as_errors: use subprocess with `-W`
2019-03-25 20:50:15 -03:00
Bruno Oliveira
bcdb86ee7e Merge pull request #4991 from blueyed/fix-tests
Fix pytest's own tests with `-W error::ResourceWarning`
2019-03-25 20:47:51 -03:00
Bruno Oliveira
2d77018d1b Improve coverage for _report_unserialization_failure 2019-03-25 20:16:59 -03:00
Bruno Oliveira
ceef0af1ae Improve coverage for to_json() with paths in reports 2019-03-25 20:16:59 -03:00
Bruno Oliveira
e4eec3416a Note that tests from xdist reference the correct xdist issues 2019-03-25 20:16:59 -03:00
Bruno Oliveira
645774295f Add CHANGELOG 2019-03-25 20:16:59 -03:00
Bruno Oliveira
f2e0c740d3 Code review suggestions 2019-03-25 20:16:59 -03:00
Bruno Oliveira
d856f4e51f Make sure TestReports are not collected as test classes 2019-03-25 20:16:59 -03:00
Bruno Oliveira
7b9a414524 Add pytest_report_serialize and pytest_report_unserialize hooks
These hooks will be used by pytest-xdist and pytest-subtests to
serialize and customize reports.
2019-03-25 20:16:59 -03:00
Bruno Oliveira
0c63f99016 Add experimental _to_json and _from_json to TestReport and CollectReport
This methods were moved from xdist (ca03269).

Our intention is to keep this code closer to the core, given that it
might break easily due to refactorings.

Having it in the core might also allow to improve the code by moving
some responsibility to the "code" objects (ReprEntry, etc) which
are often found in the reports.

Finally pytest-xdist and pytest-subtests can use those functions
instead of coding it themselves.
2019-03-25 20:16:59 -03:00
Daniel Hahler
3bc9cbea63 Merge pull request #4989 from blueyed/test_collect_capturing
test_collect_capturing: cover captured stderr
2019-03-25 23:41:53 +01:00
Daniel Hahler
6eff3069da Merge pull request #4851 from blueyed/addopts-vv
ci: PYTEST_ADDOPTS=-vv
2019-03-25 23:41:33 +01:00
Daniel Hahler
58a14b6b99 Merge pull request #4986 from blueyed/fnmatch_lines-list
tests: fnmatch_lines: use list
2019-03-25 23:31:04 +01:00
Daniel Hahler
b53bf44139 Merge pull request #4985 from blueyed/assert-from_current
ExceptionInfo.from_current: assert current exception
2019-03-25 23:28:58 +01:00
Daniel Hahler
d8758443bd Merge pull request #4983 from blueyed/coveragerc
.coveragerc: use "src" only from current dir
2019-03-25 23:28:23 +01:00
Daniel Hahler
51f64c2920 Merge pull request #4980 from blueyed/fixup_namespace_packages
monkeypatch.syspath_prepend: call fixup_namespace_packages
2019-03-25 23:10:00 +01:00
Bruno Oliveira
cea42ff9e4 Docs: modules implementing pytest_cmdline_parse can be early-loaded
Related to #4974
2019-03-25 18:43:06 -03:00
Daniel Hahler
2df9d05981 Merge pull request #4982 from blueyed/cover
Revisit coverage in some tests
2019-03-25 10:28:55 +01:00
Daniel Hahler
4142c41ffc Merge pull request #4990 from blueyed/session-repr
Session repr
2019-03-24 19:54:18 +01:00
Daniel Hahler
de44293d59 CollectError.repr_failure: honor explicit tbstyle option 2019-03-24 11:24:19 +01:00
Daniel Hahler
5efe6ab93c test_log_cli_auto_enable: get stdout once 2019-03-24 11:22:07 +01:00
Daniel Hahler
ce59f42ce1 revisit test_root_logger_affected 2019-03-24 11:21:13 +01:00
Daniel Hahler
7da7b9610c minor: whitespace 2019-03-24 11:20:24 +01:00
Daniel Hahler
d44e42ec15 doc: improve warning_record_to_str 2019-03-24 11:20:01 +01:00
Daniel Hahler
0ea1889265 test_as_errors: use subprocess with -W
Ref: https://github.com/pytest-dev/pytest/pull/4981
2019-03-24 11:17:55 +01:00
Daniel Hahler
6352cf2374 test_implicit_bad_repr1: harden/cleanup 2019-03-24 11:15:40 +01:00
Daniel Hahler
3127ec737b Fix pytest's own tests with -W error::ResourceWarning 2019-03-24 11:05:00 +01:00
Daniel Hahler
aa0b657e58 Add Session.__repr__ 2019-03-24 11:02:58 +01:00
Daniel Hahler
d0f3f26fff test_collect_capturing: cover captured stderr 2019-03-23 23:17:07 +01:00
Daniel Hahler
08f3b02dfc tests: fnmatch_lines: use list
For strings fnmatch_lines converts it into a Source objects, splitted on
newlines.  This is not necessary here, and it is more consistent to use
lists here in the first place.
2019-03-23 11:36:18 +01:00
Daniel Hahler
2d690b83bf ExceptionInfo.from_current: assert current exception 2019-03-23 00:29:36 +01:00
Daniel Hahler
0642da0145 .coveragerc: use "src" only from current dir
This avoids including generated test files with "src" in their path.
2019-03-22 17:48:14 +01:00
Daniel Hahler
afa985c135 Revisit coverage in some tests 2019-03-22 17:26:16 +01:00
Daniel Hahler
fd64fa1863 Revisit test_importplugin_error_message
Should be more helpful in case of errors than before:

    >       assert re.match(expected_message, str(excinfo.value))
    E       _pytest.warning_types.PytestWarning: asserting the value None, please use "assert is None"

    https://travis-ci.org/pytest-dev/pytest/jobs/509970576#L208
2019-03-22 17:02:26 +01:00
Daniel Hahler
56dc01ffe0 minor: revisit _possibly_invalidate_import_caches 2019-03-22 17:02:26 +01:00
Daniel Hahler
5df45f5b27 Use fixup_namespace_packages also with pytester.syspathinsert 2019-03-22 17:02:26 +01:00
Daniel Hahler
05d55b86df tests: minor sys.path cleanup 2019-03-22 16:20:55 +01:00
Daniel Hahler
475119988c monkeypatch.syspath_prepend: call fixup_namespace_packages
Without the patch the test fails as follows:

            # Prepending should call fixup_namespace_packages.
            monkeypatch.syspath_prepend("world")
    >       import ns_pkg.world
    E       ModuleNotFoundError: No module named 'ns_pkg.world'
2019-03-22 15:29:08 +01:00
Daniel Hahler
7a6bcc3639 Add reference to test_cmdline_python_namespace_package 2019-03-22 13:23:44 +01:00
Daniel Hahler
8e125c9759 doc/en/reference.rst: whitespace/alignment 2019-03-22 13:23:44 +01:00
Daniel Hahler
ade773390a minor: rename inner test 2019-03-22 13:23:44 +01:00
Daniel Hahler
5c26ba9cb1 minor: wrap_session: s/Spurious/unexpected/ 2019-03-22 13:23:44 +01:00
Daniel Hahler
5a544d4fac tox.ini: usedevelop implies skipsdist 2019-03-22 13:23:44 +01:00
Daniel Hahler
2e7d6a6202 Fix test_assertrewrite in verbose mode
Fixes https://github.com/pytest-dev/pytest/issues/4879.
2019-03-22 13:00:35 +01:00
Daniel Hahler
ea7357bc58 ci: PYTEST_ADDOPTS=-vv in general
This is useful when viewing logs, especially with hanging tests.

Uses non-verbose mode with a single job for full coverage.
2019-03-22 07:56:15 +01:00
Bruno Oliveira
b3319a6074 Merge pull request #4944 from henrykironde/k-EXPRESSION
Add example for k flag
2019-03-21 19:33:53 -03:00
Bruno Oliveira
c9628c52d6 Merge pull request #4971 from bskinn/patch-1
Fix pytestmark syntax in reference.rst
2019-03-21 18:59:25 -03:00
Brian Skinn
dcbdcc729b Fix pytestmark syntax in reference.rst
pytest 4.3.1 throws an error if `pytestmark` is set to a tuple of marks; it appears to insist on a list.



With `pytestmark = [pytest.mark.api, pytest.mark.good]`:

```
============================== test session starts ==============================
platform win32 -- Python 3.6.3, pytest-4.3.1, py-1.8.0, pluggy-0.9.0
rootdir: C:\Temp\git\sphobjinv, inifile: tox.ini
plugins: timeout-1.3.3
collected 48 items / 41 deselected / 7 selected

tests\test_api_good.py .......                                             [100%]

==================== 7 passed, 41 deselected in 0.15 seconds ====================
```


With `pytestmark = (pytest.mark.api, pytest.mark.good)`:
```
==================================== ERRORS =====================================
____________________ ERROR collecting tests/test_api_good.py ____________________
env\lib\site-packages\_pytest\runner.py:226: in from_call
    result = func()
env\lib\site-packages\_pytest\runner.py:289: in <lambda>
    call = CallInfo.from_call(lambda: list(collector.collect()), "collect")
env\lib\site-packages\_pytest\python.py:435: in collect
    self._inject_setup_module_fixture()
env\lib\site-packages\_pytest\python.py:447: in _inject_setup_module_fixture
    setup_module = _get_non_fixture_func(self.obj, "setUpModule")
env\lib\site-packages\_pytest\python.py:255: in obj
    self.own_markers.extend(get_unpacked_marks(self.obj))
env\lib\site-packages\_pytest\mark\structures.py:244: in get_unpacked_marks
    return normalize_mark_list(mark_list)
env\lib\site-packages\_pytest\mark\structures.py:259: in normalize_mark_list
    raise TypeError("got {!r} instead of Mark".format(mark))
E   TypeError: got (MarkDecorator(mark=Mark(name='api', args=(), kwargs={})), MarkDecorator(mark=Mark(name='good', args=(), kwargs={}))) instead of Mark
!!!!!!!!!!!!!!!!!!!! Interrupted: 1 errors during collection !!!!!!!!!!!!!!!!!!!!
==================== 19 deselected, 1 error in 0.27 seconds =====================
```
2019-03-21 15:14:28 -04:00
Daniel Hahler
15d608867d Merge pull request #4966 from blueyed/fix-preparse
config: fix consider_preparse with missing argument to -p
2019-03-21 19:12:57 +01:00
Daniel Hahler
ea2c6b8a88 config: fix consider_preparse with missing argument to -p
This is only required after/with 415899d4 - otherwise argparse ensures
there is an argument already.
2019-03-21 17:05:22 +01:00
Daniel Hahler
0e6cf0ff28 Merge pull request #4967 from blueyed/p-no-default
Fix some issues related to "-p no:X" with default_plugins
2019-03-21 17:02:34 +01:00
Daniel Hahler
553951c443 Fix some issues related to "-p no:X" with default_plugins 2019-03-21 17:01:50 +01:00
Bruno Oliveira
15ef168821 Merge pull request #4962 from blueyed/test_report_collect_after_half_a_second
tests: add test_report_collect_after_half_a_second
2019-03-20 19:35:08 -03:00
Daniel Hahler
cc6e5ec345 tests: add test_report_collect_after_half_a_second
This is meant for stable coverage with "collecting X item(s)".
2019-03-20 22:13:11 +01:00
Daniel Hahler
77643122a8 Merge pull request #4963 from blueyed/twisted
ci: rename "trial" tox factor to "twisted"
2019-03-20 21:58:48 +01:00
Daniel Hahler
832cef953b Merge pull request #4964 from blueyed/mkdir
Revisit mkdir/_ensure_supporting_files in cacheprovider
2019-03-20 21:58:24 +01:00
Daniel Hahler
bcdbb6b677 Revisit mkdir/_ensure_supporting_files in cacheprovider
- cacheprovider: move call to _ensure_supporting_files

  This makes it less likely to have a race here (which is not critical),
  but happened previously probably with xdist, causing flaky coverage with
  `if not readme_path.is_file():` etc checks in
  `_ensure_supporting_files`, which has been removed in the `features`
  branch already.
2019-03-20 19:00:11 +01:00
Daniel Hahler
543779fc43 tox: generic twisted factor 2019-03-20 18:41:48 +01:00
Daniel Hahler
2ade3d5c89 ci: rename "trial" tox factor to "twisted"
Ref: https://github.com/pytest-dev/pytest/pull/4848#issuecomment-467909204
2019-03-20 18:38:50 +01:00
Daniel Hahler
7939e5327c Merge pull request #4957 from blueyed/config-handle-pno-with-default-plugins
config: handle `-p no:plugin` with default plugins
2019-03-20 03:32:03 +01:00
Daniel Hahler
f7171034f9 terminal: remove unnecessary check in _get_progress_information_message
All calls to _get_progress_information_message are only done for
`_show_progress_info`, which is `False` with `capture=no`.
2019-03-20 03:04:41 +01:00
Daniel Hahler
c7c120fba6 terminal: handle "capture" option not being available
This is the case with `-p no:capture` now.
2019-03-20 03:01:26 +01:00
Daniel Hahler
415899d428 config: handle -p no:plugin with default plugins
`-p no:capture` should not load its fixtures in the first place.
2019-03-20 02:47:13 +01:00
Daniel Hahler
8dda5613ef Merge pull request #4956 from blueyed/home2
pytester: set HOME only with inline_run/popen
2019-03-20 02:29:29 +01:00
Daniel Hahler
714f2113bb Merge pull request #4929 from blueyed/fix-_factorytraceback-offset
Fix line offsets with `ScopeMismatch` errors
2019-03-20 01:30:58 +01:00
Daniel Hahler
a50b92ea67 pytester: set HOME only with inline_run/popen
Ref: https://github.com/pytest-dev/pytest/issues/4955
2019-03-20 01:15:51 +01:00
Daniel Hahler
da81c1e49a Merge pull request #4950 from blueyed/capture
Revisit capturing module: repr, doc fixes, minor
2019-03-20 01:12:22 +01:00
Bruno Oliveira
23ab43233e Merge pull request #4920 from nicoddemus/subtests-pytest-1367
Internal refactorings required for *external* pytest-subtests plugin
2019-03-19 18:57:11 -03:00
Bruno Oliveira
1a119a22d1 Internal refactorings in order to support the new pytest-subtests plugin
Related to #1367
2019-03-19 18:20:41 -03:00
Daniel Hahler
77c5191ad7 Merge pull request #4953 from blueyed/merge-master-into-features
Merge master into features
2019-03-19 04:13:31 +01:00
Daniel Hahler
7395501d1d Easier read with _colorama_workaround/_readline_workaround 2019-03-19 01:17:21 +01:00
Daniel Hahler
920bffbfbb Revisit _pytest.capture: repr, doc fixes, minor 2019-03-19 01:17:21 +01:00
Daniel Hahler
751c061d9a Merge master into features 2019-03-19 01:07:10 +01:00
Daniel Hahler
a624b84097 Merge pull request #4941 from blueyed/testdir-home
pytester: testdir: set $HOME to tmpdir
2019-03-18 23:02:15 +01:00
Daniel Hahler
c75dd10671 pytester: testdir: set $HOME to tmpdir
This avoids loading user configuration, which might interfere with test
results, e.g. a `~/.pdbrc.py` with pdb++.

Also sets USERPROFILE, which will be required with Python 3.8 [1].

1: https://bugs.python.org/issue36264
2019-03-18 20:55:39 +01:00
Bruno Oliveira
b696666f5a Merge pull request #4945 from blueyed/FDCapture-repr-None-targetfd_save
capture: fix FDCapture.__repr__ without targetfd_save
2019-03-18 13:09:30 -03:00
Bruno Oliveira
f4f6cb7532 Merge pull request #4946 from blueyed/fix-bench
Fix bench/bench.py without args
2019-03-18 13:04:12 -03:00
henrykironde
1e3d5a0412 Add example for k flag
Includes an example of multiple expressions
2019-03-17 22:33:16 -04:00
Daniel Hahler
98981276a0 capture: fix FDCapture.__repr__ without targetfd_save 2019-03-18 02:33:03 +01:00
Daniel Hahler
8c96b65082 Fix bench/bench.py without args
Fixes:

>   File "…/Vcs/pytest/src/_pytest/config/__init__.py", line 60, in main
>     config = _prepareconfig(args, plugins)
>   File "…/Vcs/pytest/src/_pytest/config/__init__.py", line 179, in _prepareconfig
>     raise TypeError(msg.format(args, type(args)))
> TypeError: `args` parameter expected to be a list or tuple of strings, got: 'empty.py' (type: <class 'str'>)
2019-03-18 02:28:41 +01:00
Bruno Oliveira
c926999cfb Merge pull request #4939 from smheidrich/mark_xfail_language
Minor grammar fixes in pytest.mark.xfail docs
2019-03-17 11:33:20 -03:00
smheidrich
519157cfcf Minor grammar fixes in pytest.mark.xfail docs 2019-03-17 10:14:40 +01:00
Bruno Oliveira
5d14362a75 Merge pull request #4936 from blueyed/use-blocked-plugin
Handle `-p plug` after `-p no:plug`
2019-03-16 12:21:33 -03:00
Daniel Hahler
15fe8c6e90 Handle -p plug after -p no:plug.
This can be used to override a blocked plugin (e.g. in "addopts") from the
command line etc.
2019-03-16 15:58:00 +01:00
Daniel Hahler
c1e01c2992 Merge pull request #4931 from blueyed/linematcher-list
pytester: LineMatcher: assert lines
2019-03-15 23:43:23 +01:00
Daniel Hahler
5e27ea5528 pytester: LineMatcher: assert Sequence when matching in order
This can be helpful when passing a set accidentally.
2019-03-15 23:07:08 +01:00
Bruno Oliveira
33d4c96aa2 Merge pull request #4830 from nicoddemus/warn-on-coroutine
Emit a warning when a coroutine test function is encountered
2019-03-15 09:51:34 -03:00
Bruno Oliveira
b3eb5d1eb7 Merge pull request #4932 from hroncok/sphinx2
Pin sphinx-removed-in to >= 0.2.0 to support Sphinx 2.0
2019-03-15 08:18:41 -03:00
Miro Hrončok
2af0a023c9 Pin sphinx-removed-in to >= 0.2.0 to support Sphinx 2.0
Fixes https://github.com/pytest-dev/pytest/issues/4912
2019-03-15 10:56:13 +01:00
Anthony Sottile
5f52d5ee17 Merge pull request #4927 from tkf/skip-doctest
Make pytest.skip work in doctest
2019-03-15 00:14:09 -07:00
Daniel Hahler
95701566f3 Update src/_pytest/outcomes.py
Co-Authored-By: tkf <takafumi.a@gmail.com>
2019-03-15 12:21:48 +09:00
Daniel Hahler
57be1d60dd Apply suggestions from code review
Co-Authored-By: tkf <takafumi.a@gmail.com>
2019-03-15 11:29:16 +09:00
Takafumi Arakaki
62f96eea6b Include documentation 2019-03-15 11:14:50 +09:00
Takafumi Arakaki
fa3cca51e1 Test pytest.skip in doctest 2019-03-15 11:06:57 +09:00
Daniel Hahler
d441fa66fe Fix line offsets with ScopeMismatch errors
Fixes https://github.com/pytest-dev/pytest/issues/4928.
2019-03-15 02:47:33 +01:00
Takafumi Arakaki
43aee15ba3 Make pytest.skip work in doctest 2019-03-15 10:20:46 +09:00
Bruno Oliveira
5c57d92978 Merge pull request #4926 from blueyed/merge-master-into-features
Merge master into features
2019-03-14 21:59:13 -03:00
Daniel Hahler
7afe17740f Merge master into features 2019-03-15 00:52:12 +01:00
Daniel Hahler
158432217c Merge pull request #4924 from blueyed/fix-pdbpp
Fix/harden some pdb tests
2019-03-15 00:51:12 +01:00
Daniel Hahler
437ff1c01a Merge pull request #4925 from blueyed/pm-super
pdb: post_mortem: use super()
2019-03-15 00:50:46 +01:00
Bruno Oliveira
40072b9511 Emit a warning when a async def function is not handled by a plugin
Fix #2224
2019-03-14 20:22:23 -03:00
Daniel Hahler
520af9d767 pdb: post_mortem: use super()
This is good practice in general, and I've seen it cause problems (MRO)
with pdb++.
2019-03-14 22:29:57 +01:00
Daniel Hahler
bdac9d3dd0 tests: improve test_pdb_interaction_doctest
- ignore pdbrc (might be done in general, but this was the only affected
  test)
- fail faster in case of unexpected failure
2019-03-14 19:16:34 +01:00
Daniel Hahler
37158f5303 tests: fix test_pdb_interaction_continue_recursive with pdbpp 2019-03-14 19:16:34 +01:00
Bruno Oliveira
612c3784e5 Merge pull request #4881 from blueyed/travis-cache
ci: Travis: disable cache by default, only for pre-commit
2019-03-14 12:39:47 -03:00
Daniel Hahler
951e07d71d Merge pull request #4919 from blueyed/opt
Optimize TracebackEntry.ishidden
2019-03-14 16:37:57 +01:00
Bruno Oliveira
36f774a8fb Merge pull request #4922 from hroncok/add_object_type
Remove deprecated Sphinx directive add_description_unit()
2019-03-14 12:31:34 -03:00
Bruno Oliveira
a2b921f890 Merge pull request #4921 from nicoddemus/mtime-test-for-4903
Add test for mtime issue in #4903
2019-03-14 10:56:08 -03:00
Bruno Oliveira
bd70f5c148 Add test for mtime issue in #4903 2019-03-14 10:16:08 -03:00
Miro Hrončok
134b957bf4 Remove deprecated Sphinx directive add_description_unit()
Partial solution for https://github.com/pytest-dev/pytest/issues/4912
2019-03-14 12:16:59 +01:00
Daniel Hahler
4d21dc4f2d Optimize TracebackEntry.ishidden
The expected behavior is that there is no "__tracebackhide__" attribute,
so use `getattr` instead of multiple try/except.
2019-03-14 01:02:46 +01:00
Bruno Oliveira
74416525d2 Merge pull request #4903 from bmwiedemann/y2038
Allow tests to pass after 2038
2019-03-13 20:07:25 -03:00
Bruno Oliveira
44cb51010c Improve CHANGELOG and code comment 2019-03-13 18:52:30 -03:00
Bruno Oliveira
90597226eb Merge pull request #4829 from nicoddemus/yield-tests-dead-code
Remove dead-code related to yield tests
2019-03-13 14:31:11 -03:00
Bruno Oliveira
7fb5ad82d9 Merge pull request #4916 from blueyed/pin-shinx
docs: pin Sphinx to <2.0
2019-03-12 22:55:24 -03:00
Daniel Hahler
f4bcb44025 docs: pin Sphinx to <2.0
Ref: https://github.com/pytest-dev/pytest/issues/4912
2019-03-13 02:36:15 +01:00
Bruno Oliveira
b7ae7a654b Remove callspec related block of code
It seems this is no longer required now that we don't support
yield tests anymore. The param attribute was added here:

91b6f2bda8/_pytest/python.py (L888-L891)
2019-03-12 20:10:59 -03:00
Bruno Oliveira
148e6a30c8 Improve coverage 2019-03-12 20:10:59 -03:00
Bruno Oliveira
47bd1688ed Remove dead-code related to yield tests
Just noticed some code that no longer is needed when we removed yield-tests
2019-03-12 20:10:59 -03:00
Daniel Hahler
6630d96253 Merge pull request #4914 from hroncok/issue4913
Fix pytest tests invocation with custom PYTHONPATH
2019-03-12 18:58:54 +01:00
Miro Hrončok
d32ab6029f Fix pytest tests invocation with custom PYTHONPATH
Fixes https://github.com/pytest-dev/pytest/issues/4913

Co-authored-by: Bruno Oliveira <nicoddemus@gmail.com>
2019-03-12 17:31:42 +01:00
Bruno Oliveira
76c00d1c09 Merge pull request #4909 from nicoddemus/release-4.3.1
Prepare release 4.3.1
2019-03-12 13:23:32 -03:00
Bruno Oliveira
492cc4219c Prepare release 4.3.1 2019-03-11 12:59:54 -03:00
Bruno Oliveira
51bf7c3aef Merge pull request #4897 from altendky/4896-altendky-add_missing_hooks_to_docs
Add missing plugin hooks to docs
2019-03-11 12:08:56 -03:00
Bernhard M. Wiedemann
489c61a22d Allow tests to pass after 2038
without this change, the python-apache-libcloud tests failed
in the year 2039 with

     fp.write(struct.pack("<ll", mtime, size))
 E   error: 'l' format requires -2147483648 <= number <= 2147483647
2019-03-10 05:22:21 +01:00
Bruno Oliveira
0f3d630634 Merge pull request #4898 from shoyer/patch-1
Fix broken error message in pytester
2019-03-08 22:53:01 -03:00
Bruno Oliveira
a0f652c559 Rename 4898.trivial.rst to 4898.bugfix.rst 2019-03-08 22:41:57 -03:00
Bruno Oliveira
877b57ae9b Add CHANGELOG entry 2019-03-08 22:33:07 -03:00
Stephan Hoyer
dc7ae41f33 Fix broken error message in pytester 2019-03-08 09:22:00 -08:00
Kyle Altendorf
2d43f42769 Add missing plugin hooks to docs
pytest-dev/pytest#4896
2019-03-08 09:24:01 -05:00
Bruno Oliveira
03ef546706 Merge pull request #4893 from nicoddemus/simplify-obj-property
Simplify 'obj' property definition in PyobjMixin
2019-03-08 02:04:28 -03:00
Daniel Hahler
de5aa3847e Apply suggestions from code review
Co-Authored-By: nicoddemus <nicoddemus@gmail.com>
2019-03-07 12:53:47 -03:00
Bruno Oliveira
0f4905a259 Simplify 'obj' property definition in PyobjMixin
This uses modern property definition syntax, declaring both getter
and setter as obj() functions
2019-03-07 08:15:04 -03:00
Bruno Oliveira
936f725b81 Merge pull request #4890 from blueyed/dead
pytester: remove unused anypython fixture
2019-03-06 14:35:23 -03:00
Daniel Hahler
c86d2daf81 pytester: remove unused anypython fixture
This became unused after ab9f6a75 (in 2009).
2019-03-06 17:42:21 +01:00
Daniel Hahler
a70c1ca100 ci: Travis: disable cache by default, only for pre-commit
For pip the usual http caching should be good enough.
This keeps the cache for pre-commit with the linting env for now.

Ref: https://github.com/pytest-dev/pytest/issues/3502
2019-03-05 23:12:11 +01:00
Daniel Hahler
4668ee03f6 Merge pull request #4887 from blueyed/merge-master-into-features
Merge master into features
2019-03-05 23:05:55 +01:00
Daniel Hahler
236bada755 Merge pull request #4768 from horta/avoid-pkg_resources
Avoid pkg_resources import at the top-level.
2019-03-05 23:02:02 +01:00
Daniel Hahler
76687030f0 Merge branch 'master' into merge-master-into-features
Conflicts:
	appveyor.yml
	setup.py
2019-03-05 19:07:36 +01:00
Daniel Hahler
2b3d69da2b Merge pull request #4865 from blueyed/revisit-cov-new
ci: revisit coverage reporting
2019-03-05 19:05:36 +01:00
Daniel Hahler
8481e438bd ci: revisit coverage reporting
This brings coverage back that got missing with 9dcd6f2.

Continuation of #4839 / #4846.
2019-03-05 13:34:46 +01:00
Daniel Hahler
bd2c9bedcf Merge pull request #4885 from blueyed/fix-master
Fix master: ci: Azure: remove pypy3
2019-03-04 19:32:38 +01:00
Daniel Hahler
2fe922608f Merge pull request #4883 from blueyed/fix-coverage-includes
.coveragerc: fix include for pypy
2019-03-04 19:31:14 +01:00
Daniel Hahler
07fa69335c ci: Azure: remove pypy3
It was enabled accidentally.
2019-03-04 18:16:20 +01:00
Daniel Hahler
ddb16a1ab1 Merge pull request #4874 from blueyed/pypy3-azure
ci: azure: fix coverage reporting with PyPy (not used currently)
2019-03-04 17:58:28 +01:00
Daniel Hahler
2e871f35f3 ci: Azure: clarify name for coverage job 2019-03-04 17:51:25 +01:00
Daniel Hahler
fa94e3c1b2 ci: Azure: fix coverage generation with PyPy
While this is not used currently, it is still good for having it covered
(it failed when running coverage with all jobs unconditionally).
2019-03-04 17:46:01 +01:00
Daniel Hahler
c6eb3413f3 .coveragerc: fix include for pypy
PyPy uses "site-packages" directly.
2019-03-04 17:40:05 +01:00
Daniel Hahler
54c70bc02c Merge pull request #4878 from blueyed/fix-test_crash_on_closing_tmpfile_py27
tests: make test_crash_on_closing_tmpfile_py27 more reliable
2019-03-04 16:22:14 +01:00
Daniel Hahler
83558a0ba3 tests: make test_crash_on_closing_tmpfile_py27 more reliable
It fails reliable for me now without the fix from 9517c3a2a.

Ref: #2370
2019-03-04 15:04:55 +01:00
Bruno Oliveira
23ea04f910 Merge pull request #4860 from nicoddemus/getfixturevalue-cleanup-1895
getfixturevalue does not correctly declare dependency with the calling fixture
2019-03-03 15:56:45 -03:00
Daniel Hahler
c334adc78f Apply suggestions from code review
Co-Authored-By: nicoddemus <nicoddemus@gmail.com>
2019-03-03 11:20:00 -03:00
Bruno Oliveira
f3f6cb2093 Merge pull request #4877 from blueyed/pluggymaster
tox: generic pluggymaster factor, remove env hack
2019-03-03 09:52:54 -03:00
Daniel Hahler
c4aa57bc4c tox/setup.py: remove _PYTEST_SETUP_SKIP_PLUGGY_DEP=1 hack 2019-03-03 13:15:13 +01:00
Daniel Hahler
2970c1df24 tox: generic pluggymaster factor 2019-03-03 13:12:44 +01:00
Bruno Oliveira
35c85f0db9 Merge pull request #4876 from nicoddemus/show-testpaths-in-header-4875
Show testpaths option in the header if it has been used for collection
2019-03-02 13:01:50 -03:00
Bruno Oliveira
0deb7b1696 Do not show "inifile:" string if there's no configuration file 2019-03-02 11:45:08 -03:00
Bruno Oliveira
53b8aa065c Show testpaths option in the header if it has been used for collection
Fix #4875
2019-03-02 11:35:32 -03:00
Bruno Oliveira
6a2d122a50 Remove code debugging leftovers 2019-03-02 09:56:15 -03:00
Bruno Oliveira
d97473e551 Add test and CHANGELOG for #1895 2019-03-02 09:39:30 -03:00
Bruno Oliveira
525639eaa0 Rename fixtures testing file to be consistent with the module name 2019-03-02 09:37:30 -03:00
Bruno Oliveira
7dceabfcb2 Ensure fixtures obtained with getfixturevalue() are finalized in the correct order
Fix #1895
2019-03-02 09:36:16 -03:00
Daniel Hahler
e1f97e41e3 Merge pull request #4872 from blueyed/_ensure_supporting_files
cacheprovider: _ensure_supporting_files: remove unused branches
2019-03-02 02:35:07 +01:00
Daniel Hahler
2d2f6cd4fd cacheprovider: _ensure_supporting_files: remove unused branches
It is only called with empty/new dirs since 0385c273.
2019-03-01 22:51:45 +01:00
Bruno Oliveira
44c940765b Merge pull request #4868 from blueyed/pytester-unset-PYTEST_ADDOPTS
pytester: unset PYTEST_ADDOPTS
2019-03-01 18:48:36 -03:00
Daniel Hahler
ed68fcf665 Merge pull request #4867 from blueyed/fix-cov
.coveragerc: use globs with includes
2019-03-01 21:35:20 +01:00
Bruno Oliveira
907e9495a2 Merge pull request #4869 from nicoddemus/tmppath-docs
Add missing ref docs to tmp_path and tmp_path_factory
2019-03-01 17:22:14 -03:00
Bruno Oliveira
dac164cc99 Add missing ref docs to tmp_path and tmp_path_factory 2019-03-01 17:09:07 -03:00
Daniel Hahler
4290cacb86 Merge pull request #4864 from blueyed/isort-cfg
Add config for isort
2019-03-01 18:44:56 +01:00
Daniel Hahler
db5cc35b44 pytester: unset PYTEST_ADDOPTS 2019-03-01 18:43:17 +01:00
Daniel Hahler
90031edde8 Merge pull request #4847 from blueyed/tox-posargs-lsof
tox: split default posargs, use --lsof with single job only
2019-03-01 18:41:29 +01:00
Daniel Hahler
a96907a9db .coveragerc: use globs with includes
Apparently this caused missing coverage with pdb/pexpect tests.
2019-03-01 18:26:30 +01:00
Daniel Hahler
f8160f7bc5 ci: Travis: run py37-lsof-numpy-xdist with coverage 2019-03-01 16:59:56 +01:00
Daniel Hahler
f0d7773ffa tox: split default posargs in multiple env vars
This is required for combining.

Use it for new lsof facor also.
2019-03-01 16:49:51 +01:00
Bruno Oliveira
84555c89de Merge pull request #4855 from blueyed/pdbcls-attr
--pdbcls: improve validation, and allow for "mod:attr.class"
2019-03-01 12:20:29 -03:00
Daniel Hahler
f7a3e001f7 pdb: allow for --pdbclass=mod:attr.class 2019-03-01 15:20:04 +01:00
Daniel Hahler
42561db1ae Merge pull request #4863 from blueyed/remove-import
Move import of  _format_explanation in _pytest.assertion.rewrite
2019-03-01 15:13:26 +01:00
Daniel Hahler
0d31e852b1 Run isort 2019-03-01 14:24:18 +01:00
Daniel Hahler
75e1fde668 tox.ini: add config for isort 2019-03-01 14:24:18 +01:00
Daniel Hahler
9cb71af9e5 _pytest.assertion.rewrite: move _format_explanation import 2019-03-01 14:13:28 +01:00
Bruno Oliveira
0dd4cb0f8f Merge pull request #4862 from blueyed/encodedfile-write-typerror
Validate type with writing to captured output like without
2019-03-01 10:12:58 -03:00
Bruno Oliveira
33db5e081d Tweak changelog 2019-03-01 10:09:29 -03:00
Daniel Hahler
a51dc0c7ce Validate type with writing to captured output like without
Fixes https://github.com/pytest-dev/pytest/issues/4861.
2019-03-01 14:03:51 +01:00
Bruno Oliveira
276ffa81f6 Merge pull request #4856 from blueyed/travis-no-cov-with-cron
ci: Travis: skip coverage with cron runs
2019-03-01 09:03:56 -03:00
Bruno Oliveira
50610311a7 Merge pull request #4859 from blueyed/tox-py27-nobyte-xdist
tox: add generic nobyte and numpy factors
2019-03-01 08:48:50 -03:00
Daniel Hahler
c30ab1014e tox: add generic nobyte and numpy factors
Remove `py27-nobyte` from tox.ini, which was using xdist already.
Therefore this also removes `py27-xdist` from Travis.

"nobyte" was added in 036557ac to test that test_assertrewrite.py works
with a global PYTHONDONTWRITEBYTECODE=1 setting.

"numpy" is only a special dependency, and can be run together with
nobyte/xdist.
2019-03-01 09:12:16 +01:00
Bruno Oliveira
df8869cf1a Merge pull request #4858 from blueyed/codecov-remove-flags
ci: codecov: remove flags completely for now
2019-02-28 20:11:09 -03:00
Daniel Hahler
8b447878dc ci: codecov: remove flags completely for now
This appears to be one of the reasons for timeouts on their backend.
2019-02-28 21:24:26 +01:00
Daniel Hahler
9c590fa474 ci: Travis: skip coverage with cron runs
The current commit on features has 50+ uploads already:
c7bbb2a788/build
2019-02-28 19:40:24 +01:00
Daniel Hahler
a868a9ac13 pdb: validate --pdbcls option 2019-02-28 18:11:58 +01:00
Bruno Oliveira
55b78ff780 Merge pull request #4848 from blueyed/fix-test_argcomplete
Fix test_argcomplete: use python -m pytest
2019-02-27 14:11:53 -03:00
Daniel Hahler
ccab469a0c Fix test_argcomplete: use python -m pytest
Previously it was not run with a) xdist ("-c"), and b) "python -m
pytest" ("…/pytest.py", not executable).
2019-02-27 16:52:46 +01:00
Daniel Hahler
e711a6c275 Merge pull request #4841 from blueyed/coverage-source
coverage: use run.include, remove --ignore-errors, send TOXENV as name to codecov
2019-02-27 13:16:31 +01:00
Daniel Hahler
c1e3128b3f Merge pull request #4844 from blueyed/tox-pexpect
tox: generic pexpect factor
2019-02-27 12:33:51 +01:00
Daniel Hahler
05bb5ffb65 Merge pull request #4842 from nicoddemus/disable-bytecode-writing
Document how to disable caching rewritten .pyc files to disk
2019-02-27 12:11:20 +01:00
Daniel Hahler
ee95d666f8 coverage: run.include, drop --ignore-errors, codecov name 2019-02-27 12:07:19 +01:00
Daniel Hahler
1e2810e07d tox: generic pexpect factor 2019-02-27 11:48:22 +01:00
Daniel Hahler
fec656b3b1 Apply suggestions from code review
Co-Authored-By: nicoddemus <nicoddemus@gmail.com>
2019-02-27 07:46:03 -03:00
Daniel Hahler
31174f3f83 .coveragerc: fix/tighten paths 2019-02-27 10:02:11 +01:00
Daniel Hahler
5a0f379289 ci: codecov: set name for uploads/builds 2019-02-27 10:02:11 +01:00
Daniel Hahler
0138e9cbb0 ci: coverage: remove --ignore-errors
This should not be necessary (anymore).
2019-02-27 09:57:28 +01:00
Daniel Hahler
b5cf61312b coverage: use source=. and report.include
This appears to improve performance - ~4s with `tox -e py37-coverage --
testing/test_collection.py`.
2019-02-27 09:57:28 +01:00
Bruno Oliveira
16cbb3196c Document how to disable caching rewritten .pyc files to disk
Also changed how the section is presented: instead of "Note" blocks, use proper
sections as those contain enough information to exist on their own.

Fix #1680
2019-02-26 20:42:59 -03:00
Bruno Oliveira
f1254c4461 Merge pull request #4840 from nicoddemus/drop-appveyor
Drop AppVeyor
2019-02-26 20:42:47 -03:00
Bruno Oliveira
cd9415baf2 Configure azure to enable coverage on PYTEST_COVERAGE=1, similar to Travis 2019-02-26 19:31:52 -03:00
Bruno Oliveira
6bd77c0abd Remove appveyor.yml and related scripts 2019-02-26 19:03:53 -03:00
Bruno Oliveira
fb7ee7f42c Add badge for azure pipelines 2019-02-26 19:01:59 -03:00
Bruno Oliveira
9dcd6f2a87 Merge pull request #4839 from blueyed/less-cov
Less coverage reporting
2019-02-26 18:57:30 -03:00
Daniel Hahler
e3eb26f91a ci: Travis: no coverage by default [skip appveyor] 2019-02-26 21:56:01 +01:00
Daniel Hahler
86070f0b7d ci: AppVeyor: no coverage reporting
Should be covered by Azure.
2019-02-26 21:16:04 +01:00
Daniel Hahler
3fbe100a02 ci: Travis: remove coverage from some jobs 2019-02-26 21:14:54 +01:00
Bruno Oliveira
ee62674322 Merge pull request #4831 from nicoddemus/codocov-azure
Upload code coverage from azure
2019-02-26 14:42:14 -03:00
Daniel Hahler
a4192160ce Merge pull request #4837 from blueyed/travis-install
ci: Travis: use single install section
2019-02-26 17:20:05 +01:00
Daniel Hahler
4d9296c71f ci: Travis: use single install section 2019-02-26 17:06:03 +01:00
Bruno Oliveira
d5d190335c Upload code coverage from azure 2019-02-26 16:56:25 +01:00
Bruno Oliveira
7428064f79 Merge pull request #4836 from blueyed/travis-pluggymaster-xdist
ci: xdist with pluggymaster
2019-02-26 12:52:59 -03:00
Bruno Oliveira
af706edd59 Merge pull request #4835 from blueyed/travis-macos
Travis: improve macos setup (py37)
2019-02-26 12:42:51 -03:00
Daniel Hahler
4eb40ef283 ci: azure: use xdist with pluggymaster 2019-02-26 14:03:15 +01:00
Daniel Hahler
f85f36ed03 AppVeyor: drop pluggymaster 2019-02-26 14:01:37 +01:00
Daniel Hahler
904f1ca1ce ci: Travis: macos: use existing py37
`brew update` and `brew upgrade python` is very slow.

This uses the existing `/usr/local/bin/python3` (3.7.0).
2019-02-26 13:55:52 +01:00
Daniel Hahler
32b85e4ccc ci: Travis: use xdist with pluggymaster jobs 2019-02-26 12:57:27 +01:00
Daniel Hahler
c7bbb2a788 Merge pull request #4833 from blueyed/merge-master
Merge master into features
2019-02-26 12:40:15 +01:00
Daniel Hahler
29112d7e0b Merge master into features 2019-02-26 11:48:10 +01:00
Bruno Oliveira
3fd2f43fb6 Merge pull request #4828 from Zac-HD/mark-docs
Clarify docs on --strict marks
2019-02-25 10:07:40 -03:00
Bruno Oliveira
2cf1de3f2d Merge pull request #4727 from nicoddemus/early-load-4718
Change -p so it is possible to early load setuptools plugins
2019-02-25 10:05:51 -03:00
Zac-HD
d9bdf5cfca Clarify docs on --strict marks 2019-02-25 22:30:49 +11:00
Anthony Sottile
f494eefcae Merge pull request #4823 from nicoddemus/unittest2env
Add unittest2 testing to trial environment
2019-02-24 10:33:26 -08:00
Anthony Sottile
c9e69438b1 Merge pull request #4822 from nicoddemus/funcsigs
Require funcsigs>=1.0 on Python 2.7
2019-02-24 09:14:09 -08:00
Bruno Oliveira
2e89812fad Add unittest2 testing to trial environment
Just noticed that `test_usefixtures_marker_on_unittest` is parametrized
for unittest2, but no environment ever installed that library.
2019-02-24 13:21:00 -03:00
Bruno Oliveira
a0207274f4 -p option now can be used to early-load plugins by entry-point name
Fixes #4718
2019-02-24 13:20:17 -03:00
Bruno Oliveira
759d7fde5d Merge pull request #4786 from blueyed/av
AppVeyor: use xdist with pypy, drop pluggymaster
2019-02-24 12:17:59 -03:00
Bruno Oliveira
a0f5c4c8f5 Merge pull request #4799 from blueyed/codecov
codecov: use only linux/windows/osx flags
2019-02-24 12:16:51 -03:00
Bruno Oliveira
2e210acd00 Merge pull request #4819 from Handsome2734/doc-fix
add notice to use [tool:pytest] in setup.cfg
2019-02-24 12:16:30 -03:00
Bruno Oliveira
ede6387caa Require funcsigs>=1.0 on Python 2.7
Fix #4815
2019-02-24 12:11:08 -03:00
Anthony Sottile
ff25b52110 Merge pull request #4820 from nicoddemus/fix-test-prefix
Fix docs about pytest conventions for test functions
2019-02-23 12:02:04 -08:00
Daniel Hahler
dc8c27037a AppVeyor: drop pluggymaster 2019-02-23 20:15:11 +01:00
Bruno Oliveira
3e11bd0d6e Update wording about [tool:pytest] in setup.cfg files 2019-02-23 15:32:42 -03:00
Bruno Oliveira
6a4c7063fd Fix docs about pytest conventions for test functions
Fix #4818
2019-02-23 15:22:27 -03:00
songbowen
15fe60aa25 add notice to use [tool:pytest] in setup.cfg 2019-02-24 00:24:56 +08:00
Daniel Hahler
1ec7f60484 codecov: use only linux/windows flags
Using many flags are a reason for timeouts on Codecov's backend.
2019-02-23 08:28:08 +01:00
Daniel Hahler
63e7f8e340 Merge pull request #4817 from nicoddemus/merge-master-into-features
Merge master into features (including fix from 4816)
2019-02-23 08:24:21 +01:00
Bruno Oliveira
1cf9c2e76f Merge pull request #4816 from nicoddemus/fix-new-pluggy
Fix test failures after pluggy 1.8 release
2019-02-22 22:42:40 -03:00
Bruno Oliveira
0ca1f6e0f4 Merge branch 'fix-new-pluggy' into merge-master-into-features 2019-02-22 18:59:51 -03:00
Bruno Oliveira
a68f4fd2b9 Fix test failures after pluggy 1.8 release
pluggy now calls iter_entry_points with different arguments, and tests
which mocked that call need to be updated accordingly.
2019-02-22 18:58:54 -03:00
Bruno Oliveira
5b35241470 Merge pull request #4812 from mitzkia/logging_from_runtest_logreport
Logging: Make pytest_runtest_logreport() hook available for logging
2019-02-22 18:47:06 -03:00
Andras Mitzki
b26b731498 Logging: Make pytest_runtest_logreport() available for logging
Signed-off-by: Andras Mitzki <andras.mitzki@balabit.com>
2019-02-22 05:14:44 +01:00
Anthony Sottile
da305966d2 Merge pull request #4793 from nicoddemus/azure-include-more-envs
Add same environments to Azure, except py37-freeze
2019-02-21 09:15:44 -08:00
Bruno Oliveira
4ee10d2266 Merge pull request #4813 from discdiver/patch-1
Doc update - recommend use venv instead of virtualenv
2019-02-21 14:06:36 -03:00
Bruno Oliveira
e1aeb6915e Fix linting 2019-02-21 13:27:12 -03:00
Bruno Oliveira
e75915bb73 Revert recommending virtualenv for Python 3.4
`venv` is already available in Python 3.4, my mistake
2019-02-21 13:03:19 -03:00
Bruno Oliveira
ba2a43266a Mention that virtualenv should be used for Python 3.4 as well 2019-02-21 12:52:09 -03:00
Jeff Hale
cfaa8bbee8 recommend venv or virtualenv, depending on python version
venv has been installed with Python since 3.3.  https://docs.python.org/3/library/venv.html
2019-02-21 10:50:49 -05:00
Jeff Hale
6b661795cf update links.inc to include both venv and virtualenv 2019-02-21 10:41:59 -05:00
Jeff Hale
fa65b71c98 Merge pull request #1 from discdiver/discdiver-patch-1
update links for virtualenv -> venv
2019-02-20 15:41:39 -05:00
Jeff Hale
da5dec83f6 update links for virtualenv -> venv 2019-02-20 15:36:34 -05:00
Jeff Hale
2ef3cb2510 Recommend use venv instead of virtualenv
From the Python docs:
"Changed in version 3.5: The use of venv is now recommended for creating virtual environments."
-https://docs.python.org/3/library/venv.html
2019-02-20 15:33:48 -05:00
Zac Hatfield-Dodds
c8a87e48ab Merge pull request #4783 from gyermolenko/fix_syntax_highlighting_for_two_rst_docs
Fix sphinx code-block types (syntax highlighting) in two docs
2019-02-20 06:31:10 +11:00
Bruno Oliveira
b9561e29ff Merge pull request #4808 from nicoddemus/merge-master-into-features
Merge master into features
2019-02-19 08:08:06 -03:00
Bruno Oliveira
bf6dcd64dc Merge pull request #4757 from blueyed/pypy
Travis: use pypy from Xenial, add pypy3
2019-02-18 19:55:43 -03:00
Daniel Hahler
214c331236 Travis: use pypy from Xenial, add pypy3 2019-02-18 22:32:31 +01:00
Bruno Oliveira
9cb504ca9a Add same environments to Azure as have in AppVeyor, except py37-freeze
py37-freeze will be tackled in https://github.com/pytest-dev/pytest/issues/4807
2019-02-18 17:23:39 -03:00
Bruno Oliveira
f0a9f9042f Merge pull request #4805 from nicoddemus/release-4.3.0
Release 4.3.0
2019-02-18 17:18:50 -03:00
Daniel Hahler
ff015f6308 Fix docs (tox -e regen, plus pre-commit) 2019-02-18 18:46:03 +01:00
Bruno Oliveira
eeac28f4ab Merge pull request #4804 from asottile/fix_py38
Fix python3.8 / pypy failures
2019-02-18 12:59:21 -03:00
Anthony Sottile
5505826db9 Fix python3.8 / pypy failures 2019-02-16 11:23:23 -08:00
Bruno Oliveira
31c869b4c4 Preparing release version 4.3.0 2019-02-16 14:11:58 +00:00
Bruno Oliveira
0395996756 Merge remote-tracking branch 'upstream/master' into release-4.3.0 2019-02-16 14:06:51 +00:00
Bruno Oliveira
986dd84375 LoggingPlugin: Support to customize log_file from hook (#4752)
LoggingPlugin: Support to customize log_file from hook
2019-02-16 12:01:21 -02:00
Bruno Oliveira
a36e986920 Merge pull request #4803 from blueyed/travis-cron
Travis: remove cron_only stage, use conditional job
2019-02-16 11:29:51 -02:00
Anthony Sottile
68dc433bf5 Merge pull request #4802 from gyermolenko/fix_code_block_in_Node_docstring
Fix code-block in Node docstring
2019-02-15 20:09:32 -05:00
Daniel Hahler
e59fc730f8 Merge pull request #4801 from gyermolenko/add_talk
Add good talk by Andrew Svetlov
2019-02-16 01:42:39 +01:00
Daniel Hahler
4f9e835472 Travis: remove cron_only stage, use conditional job
Ref: https://github.com/pytest-dev/pytest/pull/4789#issuecomment-464135675
2019-02-15 18:53:43 +01:00
Daniel Hahler
498b994eb4 Merge pull request #4787 from blueyed/travis-xdist
Travis: use xdist for py?? envs, keeping py27/py37
2019-02-15 18:35:21 +01:00
Daniel Hahler
40eef6da0c AppVeyor: use xdist for py?? envs, drop py27/py37 2019-02-15 17:55:01 +01:00
Daniel Hahler
71373b04b0 tox: add generic xdist factor
Cherry-picked from features.

Conflicts:
	tox.ini
2019-02-15 17:54:44 +01:00
Daniel Hahler
6fb7269979 terminal: write_fspath_result: work around py bug 2019-02-15 17:47:00 +01:00
Daniel Hahler
3460105def Travis: use xdist for py?? envs, keeping py27/py37 2019-02-15 17:46:58 +01:00
Andras Mitzki
e3824d23bc LoggingPlugin: Expose setting log_file_handler
- This patch allows to set log_file (path) from hook

Signed-off-by: Thomas Hisch
Signed-off-by: Andras Mitzki <andras.mitzki@balabit.com>
2019-02-15 16:05:10 +01:00
Grygorii Iermolenko
80ad448590 Fix code-block in Node docstring 2019-02-15 16:12:10 +02:00
Grygorii Iermolenko
59f69dd9e7 Add good talk by Andrew Svetlov 2019-02-15 15:37:18 +02:00
Grygorii Iermolenko
6e1ee0802f Fix sphinx code-block types for remaining rst docs 2019-02-15 15:10:37 +02:00
Grygorii Iermolenko
5cf58a9ae9 Revert '$' changes to not trigger regendoc 2019-02-15 14:09:37 +02:00
Daniel Hahler
2106515f6d Merge pull request #4796 from cclauss/patch-1
Travis CI: The 'sudo' tag is now deprecated
2019-02-14 18:06:40 +01:00
Anthony Sottile
66b4709830 Merge pull request #4798 from nicoddemus/remove-message-docs
Remove 'message' parameter docs from assert.rst
2019-02-14 09:37:22 -05:00
Daniel Hahler
0b1f813c38 Merge pull request #4784 from blueyed/fix-4782
collect: python: fix `AssertionError` with broken symlinks
2019-02-14 15:10:14 +01:00
Bruno Oliveira
0b6960446e Merge pull request #4795 from ramatevish/update-attr-kwarg
Update kwarg for attr.ib to use 'converter' as 'convert' is due to be deprecated.
2019-02-14 08:37:34 -02:00
Bruno Oliveira
4bc2f96c93 Remove 'message' parameter docs from assert.rst
As per:

	https://github.com/pytest-dev/pytest/issues/3974#issuecomment-463462732

Also made the 'match' parameter more prominent
2019-02-14 08:32:49 -02:00
cclauss
0e4750d837 Travis CI: The 'sudo' tag is now deprecated
[Travis are now recommending removing the __sudo__ tag](https://blog.travis-ci.com/2018-11-19-required-linux-infrastructure-migration).
2019-02-14 09:40:00 +01:00
R. Alex Matevish
40cec637d7 Update kwarg for attr.ib to use 'converter' as 'convert' is due to be deprecated 2019-02-14 00:03:41 -08:00
Daniel Hahler
407d4a0cf0 collect: python: fix AssertionError with broken symlinks
Fixes https://github.com/pytest-dev/pytest/issues/4782.
2019-02-14 00:18:14 +01:00
Daniel Hahler
c84ae0bb7a Merge pull request #4789 from blueyed/travis-pluggymaster-cron
Travis: add cron_only stage for py38-dev
2019-02-13 22:03:41 +01:00
Daniel Hahler
1dbf440194 Merge pull request #4785 from blueyed/merge-master-into-features
Merge master into features
2019-02-13 20:23:24 +01:00
Daniel Hahler
afaaa7e411 Travis: test py38-dev only with cron builds
The master and features branches are tested daily.
2019-02-13 19:02:02 +01:00
Daniel Hahler
7b91952645 Merge master into features
Conflicts:
	tox.ini
2019-02-13 17:58:16 +01:00
Grygorii Iermolenko
799bcccd1b Fix sphinx code-block types (syntax highlighting) in two docs 2019-02-13 17:08:49 +02:00
Bruno Oliveira
8726be27a6 Merge pull request #4779 from pytest-dev/azure-pipelines
Set up CI with Azure Pipelines [skip travis] [skip appveyor]
2019-02-13 08:39:32 -02:00
Bruno Oliveira
e26c5bda6e Merge pull request #4776 from nicoddemus/release-4.2.1
Preparing release version 4.2.1
2019-02-13 08:39:24 -02:00
Anthony Sottile
f672b7e39e Merge pull request #4773 from nicoddemus/remove-py27-py34-deprecation-warning
Remove py27 py34 deprecation warning
2019-02-12 21:42:07 -05:00
Anthony Sottile
f0e6bf7604 Merge pull request #4775 from asottile/stdlib
Replace flatten() with chain.from_iterable
2019-02-12 21:37:05 -05:00
Bruno Oliveira
f729d5d4ee Remove --color=yes from PYTEST_ADDOPTS [skip travis] [skip appveyor]
Does not work on Azure Pipelines at all unfortunately
2019-02-12 20:34:51 -02:00
Bruno Oliveira
04a941c818 Pass PYTEST_ADDOPTS to tox envs [skip travis] [skip appveyor] 2019-02-12 20:31:29 -02:00
Bruno Oliveira
215d537624 Set junitxml and colors using PYTEST_ADDOPTS [skip travis] [skip appveyor] 2019-02-12 20:24:32 -02:00
Bruno Oliveira
f63fbf8114 Merge pull request #4767 from blueyed/appveyor-xdist
AppVeyor: use xdist for py?? envs, drop py27/py37
2019-02-12 20:04:45 -02:00
Bruno Oliveira
b595587031 Set up CI with Azure Pipelines [skip travis] [skip appveyor]
Just a few environments for now to see how it will behave for a few days
2019-02-12 20:01:13 -02:00
Bruno Oliveira
82cc3d8cc2 Preparing release version 4.2.1 2019-02-12 20:17:06 +00:00
Bruno Oliveira
e20e376881 Merge pull request #4347 from blueyed/pdb-recursive-capture
pdbpp: fix capturing with recursive debugging
2019-02-12 16:53:14 -02:00
Bruno Oliveira
8052d01a37 Merge pull request #4774 from sambrightman/pin-more_itertools
Constrain more_itertools for Python 2.7 compatibility
2019-02-12 16:48:51 -02:00
Bruno Oliveira
d03444db4a Merge pull request #4651 from blueyed/help-with-argumenterror
Display --help/--version with ArgumentErrors
2019-02-12 16:01:49 -02:00
Anthony Sottile
f9c1329dab Replace flatten() with chain.from_iterable
flatten is an alias in more-itertools anyway
2019-02-12 06:30:00 -08:00
Sam Brightman
a8003286b5 Add CHANGELOG entry for #4770 2019-02-12 13:32:06 +00:00
Daniel Hahler
747a8ae3a6 AppVeyor: use xdist for py?? envs, drop py27/py37 2019-02-12 14:26:57 +01:00
Bruno Oliveira
b759ebdb93 Add CHANGELOG entry for #4698 2019-02-12 10:39:58 -02:00
Bruno Oliveira
b41632e9a8 Revert "Show deprecation message when running under Python 2.7 and 3.4"
This reverts commit eb92e57509.
2019-02-12 10:39:25 -02:00
Sam Brightman
b4be228330 Constrain more_itertools for Python 2.7 compatibility
Fixes #4772, #4770.
2019-02-12 11:53:23 +00:00
Danilo Horta
821b6ef2a6 Avoid pkg_resources import at the top-level. 2019-02-11 23:26:35 +00:00
Daniel Hahler
31c948184a Merge pull request #4753 from blueyed/tox-xdist
tox: add generic xdist factor
2019-02-11 23:36:59 +01:00
Bruno Oliveira
67dd10de26 Merge pull request #4763 from blueyed/lsof
--lsof: suppress stderr
2019-02-11 13:18:40 -02:00
Daniel Hahler
f13935da53 Display --help/--version with ArgumentErrors 2019-02-11 15:49:48 +01:00
Daniel Hahler
dc8af18a0e Merge pull request #4745 from blueyed/test_collect_pkg_init_and_file_in_args
Fix handling of pkg init and test file via args
2019-02-11 15:11:40 +01:00
Daniel Hahler
7bee359459 tox: add generic xdist factor 2019-02-11 15:09:07 +01:00
Daniel Hahler
61b9246afe Fix/improve handling of pkg init and test file via args
Ref: https://github.com/pytest-dev/pytest/issues/4344#issuecomment-441095934
2019-02-11 15:04:24 +01:00
Daniel Hahler
9feb4941f4 pdb: fix capturing with recursive debugging and pdb++
While I think that pdb++ should be fixed in this regard (by using
`pdb.Pdb`, and not `self.__class__` maybe), this ensures that custom
debuggers like this are working.
2019-02-11 14:52:20 +01:00
Daniel Hahler
237f690f8b --lsof: suppress stderr
This can spam a lot of warnings (per invocation), e.g.:

> lsof: WARNING: can't stat() nsfs file system /run/docker/netns/default
        Output information may be incomplete.

Or from Travis/MacOS:

> lsof: WARNING: can't stat() vmhgfs file system /Volumes/VMware Shared Folders
>       Output information may be incomplete.
>       assuming "dev=31000003" from mount table
2019-02-11 14:08:44 +01:00
Ronny Pfannschmidt
386e801a5a Merge pull request #4762 from blueyed/pluggymaster
tox: use deps for pluggymaster testenvs
2019-02-11 05:30:30 +01:00
Bruno Oliveira
5cf05ce149 Merge pull request #4764 from kevinjfoley/doc-assert-clarify
Clarify pytest_assertrepr_compare docs per #4759
2019-02-10 17:26:50 -02:00
Kevin J. Foley
aee67bb1a7 Clarify pytest_assertrepr_compare docs per #4759 2019-02-10 08:34:35 -05:00
Daniel Hahler
5e2d740829 tox: cleanup/revisit deps 2019-02-10 14:02:56 +01:00
Daniel Hahler
82b8ec37fc Bump tox minversion
For c611a16afe
2019-02-10 13:57:49 +01:00
Daniel Hahler
f73fa47b1f Use coverage with pluggymaster 2019-02-10 13:54:58 +01:00
Daniel Hahler
fd1684e70b tox: use deps for pluggymaster testenvs
https://github.com/tox-dev/tox/issues/706 has been fixed.
2019-02-10 13:53:49 +01:00
Anthony Sottile
19501028ca Merge pull request #4743 from nicoddemus/junit-ref
Document junit_family option in the reference docs
2019-02-09 08:02:55 -08:00
Daniel Hahler
ed01dc6567 Merge pull request #4652 from blueyed/RunResult-repr
Add __repr__ for RunResult
2019-02-09 01:26:24 +01:00
Bruno Oliveira
3a366f451a Merge pull request #4741 from thisch/refactor_terminalreporter
Remove terminal_reporter workaround from logging.py
2019-02-08 21:47:53 -02:00
Bruno Oliveira
7f6108beb1 Add ref docs for junit_family option 2019-02-08 21:44:52 -02:00
Bruno Oliveira
76b0660f47 Merge pull request #4754 from nicoddemus/ignore-pip-wheel-metadata
Ignore pip-generated 'pip-wheel-metadata' folder [skip ci]
2019-02-08 21:37:04 -02:00
Daniel Hahler
fc8800c71f Merge pull request #4722 from fetzerch/ignore_wildcards
Add ability to use globs when using --ignore
2019-02-09 00:11:04 +01:00
Bruno Oliveira
75a12b9d2b Ignore pip-generated 'pip-wheel-metadata' folder [skip ci] 2019-02-08 21:06:33 -02:00
Daniel Hahler
9bcbf552d6 Add __repr__ for RunResult 2019-02-08 23:41:20 +01:00
Bruno Oliveira
32c6d4f603 Merge pull request #4738 from pstradomski/master
Fix "ValueError: Plugin already registered" exceptions when running in build directories that symlink to actual source.
2019-02-08 19:57:14 -02:00
Daniel Hahler
b4b2f58eab Merge pull request #4747 from blueyed/visit-filter
pytest.main: collect: factor out _visit_filter
2019-02-08 22:19:38 +01:00
Daniel Hahler
a131cd6c3b Merge pull request #4749 from blueyed/merge-master-into-features
Merge master into features
2019-02-08 22:05:43 +01:00
Daniel Hahler
9c03196e79 Merge master into features 2019-02-08 22:02:29 +01:00
Daniel Hahler
8b92d10fb3 Merge pull request #4751 from blueyed/fix-py-freeze
tox: py37-freeze: use --no-use-pep517 for PyInstaller
2019-02-08 22:01:59 +01:00
Bruno Oliveira
8e220f0e6f Merge pull request #4746 from nicoddemus/isolated-build
Use isolated_build option in tox.ini
2019-02-08 18:59:43 -02:00
Daniel Hahler
e191a65ebb tox: py37-freeze: use --no-use-pep517 for PyInstaller
Fixes https://github.com/pytest-dev/pytest/issues/4750.
2019-02-08 21:59:23 +01:00
Daniel Hahler
5ca81596bb Merge pull request #4744 from blueyed/fix-4592-collectfile
Fix handling of collect_ignore from parent conftest
2019-02-08 20:58:11 +01:00
Daniel Hahler
64e8185ff7 Merge master into features 2019-02-08 20:09:09 +01:00
Daniel Hahler
7bb504b807 pytest.main: collect: factor out _visit_filter 2019-02-08 19:28:12 +01:00
Bruno Oliveira
9be069f899 Use isolated_build option in tox.ini
As per the excellent article by gaborbernat:

https://www.bernat.tech/pep-517-518/
2019-02-08 15:50:33 -02:00
Daniel Hahler
913a2da6e5 Fix handling of collect_ignore from parent conftest
`_collectfile` should be called on files only.

Fixes https://github.com/pytest-dev/pytest/issues/4592.
2019-02-08 18:46:43 +01:00
Anthony Sottile
ea732464aa Merge pull request #4740 from asottile/bugfix_4739
Fix `parametrize(... ids=<function>)` when the function returns non-strings
2019-02-07 21:47:33 -08:00
Thomas Hisch
ddbea29c12 Remove terminal_reporter workaround from logging.py
The workaround was removed from the logging module by creating python
properties for verbosity related settings in the terminalreporter.

Closes: #4733
2019-02-07 22:52:07 +01:00
Anthony Sottile
4c7ddb8d9b Fix parametrize(... ids=<function>) when the function returns non-strings. 2019-02-07 12:25:59 -08:00
Thomas Hisch
a1fcd6e445 Merge pull request #4734 from thisch/refactor_clilogging
Refactor _setup_cli_logging code
2019-02-07 20:15:41 +01:00
Thomas Hisch
7b8fd0cc12 Refactor _setup_cli_logging code
Change the indentation in _setup_cli_logging by moving the
self._log_cli_enabled check outside of the _setup_cli_logging method.
2019-02-07 19:39:12 +01:00
Paweł Stradomski
391dc549c0 Add comment on why realpath is needed 2019-02-07 12:56:13 +01:00
Ronny Pfannschmidt
526f4a95cc Merge pull request #4735 from kohr-h/pytest_plugins_module_name
Mention that `pytest_plugins` should not be used as module name
2019-02-07 07:07:58 +01:00
Ronny Pfannschmidt
4cd268dc5d Merge pull request #4724 from nicoddemus/pytest-warns-kwargs
emit warning when pytest.warns receives unknown keyword arguments
2019-02-07 07:04:25 +01:00
Paweł Stradomski
59e6fb94b5 Fix "ValueError: Plugin already registered" exceptions when running in build directories that symlink to actual source. 2019-02-07 02:05:22 +01:00
Bruno Oliveira
2f083504ee Merge pull request #4709 from namurphy/warns-docs
Document how to customize test failure message for missing warnings
2019-02-06 20:51:14 -02:00
Zac Hatfield-Dodds
3384ffc6eb Merge pull request #4725 from nicoddemus/collection-finish
Call pytest_report_collectionfinish hook when --collect-only is passed
2019-02-06 12:38:12 -10:00
Bruno Oliveira
e276bd3332 pytest.warns emits a warning on unknown keyword arguments 2019-02-06 19:52:13 -02:00
Holger Kohr
7445b5345f Mention that pytest_plugins should not be used as module name 2019-02-06 21:57:42 +01:00
Ronny Pfannschmidt
429485e621 Merge pull request #4720 from thisch/removesetupclilogging
Only call _setup_cli_logging in __init__
2019-02-06 20:05:41 +01:00
Bruno Oliveira
52d497570b Merge pull request #4731 from nicoddemus/travis-py38
Add py38-dev job to Travis
2019-02-06 16:24:07 -02:00
Christian Fetzer
1876a928d3 Document collect_ignore and collect_ignore_glob in reference 2019-02-06 17:15:30 +01:00
Christian Fetzer
2dc2a19db5 Add ability to exclude files matching glob patterns in conftest.py
This adds the `collect_ignore_glob` option for `conftest.py` to allow
Unix-style wildcards for excluding files.
2019-02-06 16:49:43 +01:00
Bruno Oliveira
0c5e717f43 Add py38-dev job to Travis 2019-02-06 13:11:00 -02:00
Bruno Oliveira
54af0f4c65 Call pytest_report_collectionfinish hook when --collect-only is passed
Fix #2895
2019-02-06 12:58:23 -02:00
Bruno Oliveira
678dfaa6eb Merge pull request #4728 from nicoddemus/usage-error-module
Do not raise UsageError when "pytest_plugins" is a module
2019-02-06 12:22:12 -02:00
Christian Fetzer
fc5d4654e5 Add ability to exclude files matching glob patterns with --ignore-glob
This adds the `--ignore-glob` option to allow Unix-style wildcards so
that `--ignore-glob=integration*` excludes all tests that reside in
files starting with `integration`.

Fixes: #3711
2019-02-06 11:29:30 +01:00
Bruno Oliveira
19c93d16d1 Do not raise UsageError when "pytest_plugins" is a module
Fix #3899
2019-02-06 08:24:22 -02:00
Thomas Hisch
0ce8b910ca Only call _setup_cli_logging in __init__
Supersedes #4719
2019-02-06 07:03:40 +01:00
Anthony Sottile
c780d1fa7c Merge pull request #4723 from asottile/docstring_fix_py38
Remove workaround for docstrings for py38+
2019-02-05 15:23:48 -08:00
Bruno Oliveira
584c052da4 Fix linting and change False to True as requested in review 2019-02-05 19:04:26 -02:00
Anthony Sottile
315374008b Remove workaround for docstrings for py38+ 2019-02-05 12:48:18 -08:00
Ronny Pfannschmidt
a9457345ee Merge pull request #4715 from nicoddemus/fix-changelog-typo
Fix typo in CHANGELOG
2019-02-04 13:53:48 +01:00
Bruno Oliveira
726e165932 Fix typo in CHANGELOG 2019-02-04 08:38:48 -02:00
Anthony Sottile
2264db7f4a Merge pull request #4682 from arel/parameterize-conditional-raises-document-only
Document parametrizing conditional raises
2019-02-02 13:15:26 -08:00
Nick Murphy
4e93dc2c97 Update changelog for pytest.warns doc update 2019-02-01 22:11:41 -05:00
Nick Murphy
8003d8d279 Update AUTHORS 2019-02-01 21:55:01 -05:00
Nick Murphy
f0ecb25acd Document custom failure messages for missing warnings 2019-02-01 21:48:29 -05:00
Arel Cordero
7ec1a1407a Incorporating feedback from asottile 2019-02-02 01:57:17 +00:00
Bruno Oliveira
7dbe40092d Merge pull request #4703 from nicoddemus/setup-class-inheritance-4700
Fix setUpClass being called in subclasses that were skipped
2019-02-01 16:32:27 -02:00
Bruno Oliveira
e53563ebbe Merge pull request #4706 from hackebrot/add-xfail-note-to-4.2.0-changelog
Update changelog to reflect spelling change of xfail
2019-02-01 10:35:46 -02:00
Raphael Pierzina
c2c9b27771 Update changelog to reflect spelling change of xfail in teststatus report
Resolve #4705
2019-02-01 13:15:35 +01:00
Bruno Oliveira
c3d7340542 Fix setUpClass being called in subclasses that were skipped
Fix #4700
2019-01-31 20:24:11 -02:00
Bruno Oliveira
2461a43e00 Merge pull request #4697 from nicoddemus/merge-master-into-features
Merge master into features
2019-01-31 17:10:35 -02:00
Bruno Oliveira
7dcd9bf5ad Merge pull request #4696 from nicoddemus/release-4.2.0
Release 4.2.0
2019-01-30 19:37:00 -02:00
Bruno Oliveira
fa979a4290 Preparing release version 4.2.0 2019-01-30 14:25:38 -02:00
Bruno Oliveira
e2a15c79e7 Merge pull request #4692 from nicoddemus/merge-master-into-features
Merge master into features
2019-01-30 14:16:09 -02:00
Bruno Oliveira
02962fabda Merge remote-tracking branch 'upstream/features' into merge-master-into-features 2019-01-30 09:37:46 -02:00
Bruno Oliveira
b77d168d58 Merge remote-tracking branch 'upstream/master' into merge-master-into-features 2019-01-30 09:37:29 -02:00
Bruno Oliveira
c0e6543b5a Fix pytest_report_teststatus call to pass new config object (#4691) 2019-01-30 09:36:54 -02:00
Bruno Oliveira
b96e162131 Merge pull request #4693 from asottile/flake8_3_7_0
fixes for flake8 3.7
2019-01-30 09:18:09 -02:00
Bruno Oliveira
1dc16ad77b Merge pull request #4690 from nicoddemus/deprecated-python-summary
Show deprecation message when running under Python 2.7 and 3.4
2019-01-30 09:07:59 -02:00
Anthony Sottile
acece23697 pre-commit autoupdate 2019-01-29 21:13:32 -08:00
Anthony Sottile
e5f823a3a7 fixes for flake8 3.7 2019-01-29 21:11:15 -08:00
Bruno Oliveira
b41dc03930 Merge pull request #4691 from nicoddemus/config-terminal-summary-hook
Add config to pytest_terminal_summary hook
2019-01-29 21:11:37 -02:00
Bruno Oliveira
ade5f2c8c5 Merge remote-tracking branch 'upstream/master' into merge-master-into-features 2019-01-29 19:36:56 -02:00
Bruno Oliveira
3e0e819158 Merge pull request #4280 from blueyed/trace-quit
pdb: improve quitting from debugger
2019-01-29 19:14:20 -02:00
Bruno Oliveira
eb92e57509 Show deprecation message when running under Python 2.7 and 3.4
Fix #4627
2019-01-29 19:02:41 -02:00
Bruno Oliveira
7ad499ad76 Merge pull request #4681 from RonnyPfannschmidt/fix-4680-tmppath-is-tmpdir
Fix 4680 - `tmp_path` and `tmpdir` now share the same temporary directory
2019-01-29 19:00:56 -02:00
Ronny Pfannschmidt
2d7582bd92 flip around basetemp folder reset to see if it helps on windows 2019-01-29 18:58:00 +01:00
Bruno Oliveira
7e8e593a45 Add CHANGELOG entry for #4691 2019-01-29 15:52:45 -02:00
Bruno Oliveira
6c3b86369f Add config to pytest_terminal_summary hook
The docs stated that this hook got the 'config' parameter in 3.5, but the docs
wre probably changed by mistake.
2019-01-29 15:41:13 -02:00
Bruno Oliveira
6aba60ab08 Merge pull request #4688 from nicoddemus/add-config-to-hooks
Add config to pytest_report_teststatus
2019-01-28 21:45:58 -02:00
Bruno Oliveira
d720312df0 Add CHANGELOG entry for #4688 2019-01-28 19:03:19 -02:00
Bruno Oliveira
5b09eb1d74 Add config parameter to pytest_report_teststatus hook 2019-01-28 19:00:50 -02:00
Bruno Oliveira
5119abe498 Merge pull request #4683 from nicoddemus/skip-unicode
Handle unittest.SkipTest exception with non-ascii characters
2019-01-28 15:50:53 -02:00
Bruno Oliveira
1c5009c3fb Handle unittest.SkipTest exception with non-ascii characters
Fix #4669
2019-01-28 12:50:04 -02:00
Arel Cordero
8a1afe4213 Including note on using nullcontext in Python 3.7+ 2019-01-28 13:31:08 +00:00
Arel Cordero
fd4289dae0 Adding does_not_raise to documentation only 2019-01-27 16:42:10 +00:00
Arel Cordero
977adf1354 Improving sphinx docs based on feedback 2019-01-27 16:41:23 +00:00
Arel Cordero
c1fe07276c Adding changelog entries for does_not_raise 2019-01-27 16:41:10 +00:00
Arel Cordero
c166b80a8c Documenting raises/does_not_raise + parametrize 2019-01-27 16:40:49 +00:00
Arel Cordero
afe9fd5ffd Adds does_not_raise context manager
Addressing issues #4324 and #1830
2019-01-27 16:40:35 +00:00
Ronny Pfannschmidt
5567c772cd quick&dirty fix fixture tests that rely on tmppath fixture structure 2019-01-27 14:19:23 +01:00
Ronny Pfannschmidt
c75bd08807 ensure tmp_path is always a realpath 2019-01-27 14:08:43 +01:00
Ronny Pfannschmidt
f7d7555521 fix #4680 - ensure tmpdir and tmp_path are the same 2019-01-27 13:05:34 +01:00
Anthony Sottile
16f8cdac95 Merge pull request #4678 from nicoddemus/raises-docs
Improve pytest.raises 'message' deprecation docs
2019-01-26 19:01:21 -08:00
Bruno Oliveira
9905a73ae0 Merge pull request #4511 from jhunkeler/junit-strict
Toggle JUnit behavior with INI option
2019-01-24 20:54:32 -02:00
Bruno Oliveira
51dd738b1a Merge pull request #4673 from kown7/count-tests
Count tests
2019-01-24 20:46:29 -02:00
Bruno Oliveira
067f2c6148 Improve pytest.raises 'message' deprecation docs
Based on recent discussions in #3974
2019-01-24 20:41:18 -02:00
Kristoffer Nordstroem
e2cd2cd409 vanity commit 2019-01-24 23:18:21 +01:00
Bruno Oliveira
37aab5dd6b Add CHANGELOG entry for #4660 2019-01-24 20:07:21 -02:00
Bruno Oliveira
7ddfc04793 Merge pull request #4665 from nicoddemus/group-warnings-by-message
Group warnings by message instead of by test id
2019-01-24 20:00:27 -02:00
Bruno Oliveira
7b10474fed Merge pull request #4668 from wimglenn/issues/4667
short report summary to use report teststatus data
2019-01-24 19:59:52 -02:00
wim glenn
8cf097635e Fixed one weird test that creates a class instead of using mocks.. ¯\_(ツ)_/¯ 2019-01-24 12:59:36 -06:00
wim glenn
2d18546870 resolving report.when attribute should be reliable now 2019-01-24 11:12:59 -06:00
wim glenn
0f546c4670 pytest_terminal_summary uses result from pytest_report_teststatus hook, rather than hardcoded strings
Less hacky way to make XPASS yellow markup. Make sure collect reports still have a "when" attribute.

xfail changed to XFAIL in the test report, for consistency with other outcomes which are all CAPS
2019-01-24 10:17:29 -06:00
Kristoffer Nordstroem
6d38868950 fix tests by adding additional output to expected responses 2019-01-24 00:08:43 +01:00
Kristoffer Nordstroem
8723eb16ea only print selected if any have been selected 2019-01-24 00:00:29 +01:00
Bruno Oliveira
daf39112e7 Merge pull request #4091 from nicoddemus/setup-methods-as-fixtures-3094
Use fixtures to invoke xunit-style fixtures
2019-01-23 19:23:31 -02:00
Bruno Oliveira
9543d1901f Group warnings by message instead of by test id 2019-01-22 19:42:22 -02:00
Anthony Sottile
ba452dbcf0 Merge pull request #4664 from thisch/stdlibtest
Remove stdlib test
2019-01-22 11:28:51 -08:00
Thomas Hisch
a2954578aa Remove stdlib test 2019-01-22 20:25:51 +01:00
Anthony Sottile
1bcb2f91cc Merge pull request #4661 from asottile/more_py
remove and ban py.io.BytesIO, py.process, py.path.local.sysfind
2019-01-21 22:58:43 -08:00
Anthony Sottile
92a2c1a9c4 remove and ban py.io.BytesIO, py.process, py.path.local.sysfind 2019-01-21 19:51:16 -08:00
Kristoffer Nordstroem
9f86e83478 count selected tests 2019-01-21 23:56:39 +01:00
Anthony Sottile
f01f434311 Merge pull request #4657 from asottile/py_io_saferepr
copy saferepr from pylib
2019-01-21 13:25:02 -08:00
Anthony Sottile
0c6ca0da62 Fix usages of py.io.saferepr 2019-01-20 16:36:23 -08:00
Anthony Sottile
095ce2ca7f Fix linting errors and py references in saferepr.py 2019-01-20 16:36:14 -08:00
Anthony Sottile
dbb6c18c44 copy saferepr from pylib verbatim
Copied from b9da2ed6178cd37d4ed6b41f9fa8234dce96973f
2019-01-20 16:30:31 -08:00
Anthony Sottile
653c685667 Merge pull request #4658 from asottile/py_deprecated_builtin
Remove and ban use of py.builtin
2019-01-20 14:29:00 -08:00
Anthony Sottile
ec5e279f93 Remove and ban use of py.builtin 2019-01-20 11:59:48 -08:00
Daniel Hahler
e69b1255d7 Improve quitting from pdb
Regarding tests: it merges ``test_pdb_interaction``,
``test_pdb_print_captured_stdout``, and
``test_pdb_print_captured_stderr`` into
``test_pdb_print_captured_stdout_and_stderr`` (clarity and performance,
especially since pexpect tests are slow).
2019-01-20 00:34:16 +01:00
Bruno Oliveira
57bf9d6740 Merge pull request #4654 from AuHau/fix/#4653-Fix_tmp_path_symlink_resolution
Fixes #4653 - tmp_path provides real path
2019-01-19 09:41:47 -02:00
Bruno Oliveira
677a7d06da Merge pull request #4655 from RonnyPfannschmidt/fix-4649
fix #4649 - also transfer markers to keywordmapping
2019-01-19 09:40:03 -02:00
Ronny Pfannschmidt
f28b834426 fix #4649 - also transfer markers to keywordmapping
as it turns out it is distinct from nodekeywords and behaves completely different
2019-01-18 23:18:51 +01:00
Adam Uhlir
04bd147d46 Fixes #4653 - tmp_path provides real path 2019-01-18 12:54:00 -08:00
Bruno Oliveira
6154a5ac02 Merge pull request #4646 from nicoddemus/2.7-deprecation-docs
Add docs page about plans for dropping py27 and py34
2019-01-16 12:00:09 -02:00
Bruno Oliveira
1a04e8903a Merge pull request #4537 from chdsbd/master
Bugfix: monkeypatch.delattr handles class descriptors
2019-01-16 08:09:59 -02:00
Joseph Hunkeler
85c5fa9f64 Update changelog 2019-01-14 22:58:41 -05:00
Joseph Hunkeler
8967976443 Ensure xml object is viable before testing family type 2019-01-14 22:58:41 -05:00
Joseph Hunkeler
bcacc40775 Update comment text 2019-01-14 22:58:41 -05:00
Joseph Hunkeler
4ecf29380a Adds xunit2 version of test_record_attribute 2019-01-14 22:58:41 -05:00
Joseph Hunkeler
aaa7d36bc9 Change family behavior:
* "legacy" is no longer a copy of "xunit1"
* Attempts to use "legacy" will redirect to "xunit1"
* record_xml_attribute is not compatible outside of legacy family
* Replace call to method/override raw() with to_xml()
2019-01-14 22:58:40 -05:00
Joseph Hunkeler
8937e39afd Raise TypeError instead of NotImplementedError if not list type 2019-01-14 22:58:40 -05:00
Joseph Hunkeler
343430c537 Replace family "old" with "legacy" 2019-01-14 22:58:40 -05:00
Joseph Hunkeler
335cc5d651 Handle backwards-compatiblity 2019-01-14 22:58:40 -05:00
Joseph Hunkeler
2e551c32b6 Add junit_family config option 2019-01-14 22:58:40 -05:00
Joseph Hunkeler
af2ee1e80a Emit JUnit compatible XML
* Remove non-standard testcase elements: 'file' and 'line'
* Replace testcase element 'skips' with 'skipped'
* Time resolution uses the standard format: 0.000
* Tests use corrected XML output with proper attributes
2019-01-14 22:58:40 -05:00
Bruno Oliveira
e2a9aaf24b Add docs page about plans for dropping py27 and py34
Fix #4635
2019-01-14 22:10:15 -02:00
Anthony Sottile
4947eb85c0 Merge pull request #4645 from blueyed/merge-master-into-features
Merge master into features
2019-01-14 14:41:27 -08:00
Daniel Hahler
1a358df998 Merge master into features 2019-01-14 17:15:39 +01:00
Anthony Sottile
5903f4596a Merge pull request #4643 from nicoddemus/asscalar-deprecated
Use a.item() instead of deprecated np.asscalar(a)
2019-01-14 07:36:13 -08:00
Anthony Sottile
5bb0be1e24 Merge pull request #4615 from asottile/some_dead_code
Remove some dead code
2019-01-14 07:35:21 -08:00
Bruno Oliveira
6504746652 Add CHANGELOG entry for #4643 2019-01-14 09:03:23 -02:00
Bruno Oliveira
42bb0b3904 Use a.item() instead of deprecated np.asscalar(a)
np.asscalar() has been deprecated in numpy 1.16:

https://github.com/numpy/numpy/blob/master/doc/release/1.16.0-notes.rst#new-deprecations
2019-01-14 08:59:09 -02:00
Bruno Oliveira
1bb463a980 Merge pull request #4642 from nicoddemus/rtd-bot-config
Add rtd-bot configuration file
2019-01-14 05:57:50 -02:00
Anthony Sottile
16546b7342 Remove some dead code
- I wrote a thing: https://github.com/asottile/dead
- wanted to try it out, there's lots of false positives and I didn't look
  through all the things it pointed out but here's some
2019-01-13 20:41:30 -08:00
Bruno Oliveira
f2174c16cc Add rtd-bot configuration file [skip appveyor] [skip travis]
Part of the configuration necessary for https://github.com/apps/rtd-helper
2019-01-13 20:38:19 -02:00
Bruno Oliveira
e48f68953d Merge pull request #4638 from nicoddemus/release-4.1.1
Preparing release version 4.1.1
2019-01-12 12:51:32 -02:00
Bruno Oliveira
25081d8e30 Merge pull request #4570 from nicoddemus/sphinx-removed-in
Use sphinx removed in extension in the documentation
2019-01-12 08:34:29 -02:00
Bruno Oliveira
34eeda1c09 Preparing release version 4.1.1 2019-01-12 00:55:12 +00:00
Bruno Oliveira
3efb26ae7f Merge pull request #4632 from AnjoMan/dont-rewrite-objects-with-failing-getattr
Assertion rewrite breaks for objects that reimplement `__getattr__`
2019-01-11 14:07:22 -02:00
Anton Lodder
77da4f118c Add changelog 4631 and AUTHOR credits for Anton Lodder 2019-01-10 20:48:51 -05:00
Anton Lodder
3241fc3103 Don't fail if hasattr fails when rewriting assertions
When rewriting assertions, pytest makes a call to
`__name__` on each object in a comparision. If one of
the objects has reimplemented `__getattr__`, they could
fail trying to fetch `__name__` with an error other than
`AttributeError`, which is what `hasattr` catches.

In this case, the stack trace for the failed `__getattr__`
call will show up in the pytest output, even though
it isn't related to the test failing.

This change fixes that by catching exceptions
that `hasattr` throws.
2019-01-10 20:45:15 -05:00
Anton Lodder
acb3e8e8a7 Test rewriting assertion when __name__ fails
Pytest rewrites assertions so that the items on each
side of a comoparison will have easier-to-read names
in case of an assertion error.

Before doing this, it checks to make sure the object
doesn't have a __name__ attribute; however, it uses
`hasattr` so if the objects __getattr__ is broken then
the test failure message will be the stack trace
for this failure instead of a rewritten assertion.
2019-01-10 20:45:15 -05:00
Bruno Oliveira
5f16ff3acc Merge pull request #4212 from RonnyPfannschmidt/doctest-testmod-has-call
Doctest: hack in handling mock style objects
2019-01-10 19:13:45 -02:00
Bruno Oliveira
71a745270a Merge pull request #4607 from oscarbenjamin/long_output
Show full repr with assert a==b and -vv
2019-01-10 12:30:46 -02:00
Bruno Oliveira
5dcb370f78 Merge pull request #4624 from nicoddemus/merge-master-into-features
Merge master into features
2019-01-10 12:11:20 -02:00
Bruno Oliveira
0f918b1a9d xunit-style functions and methods are invoked by autouse fixtures
Fix #3094, Fix #517
2019-01-10 12:10:04 -02:00
Ronny Pfannschmidt
a6988aa0b9 fix doctest module when a mock object is around
fixes #3456
2019-01-10 12:50:22 +01:00
Bruno Oliveira
2359663437 Merge pull request #4622 from nicoddemus/warningschecker-unittest
Change test_warningschecker_twice to a unittest
2019-01-10 06:04:25 -02:00
Anthony Sottile
bace28517e Merge pull request #4626 from nicoddemus/goodpractices-pythonpath
Mention PYTHONPATH semantics in goodpractices.rst
2019-01-09 20:41:53 -08:00
Bruno Oliveira
9f6d9efc1d Mention PYTHONPATH semantics in goodpractices.rst
Fix #4625
2019-01-09 22:45:09 -02:00
Bruno Oliveira
a0ab5a7cd8 Merge pull request #4609 from yoavcaspi/documentation-configuration-files
Documentation configuration files
2019-01-09 22:32:02 -02:00
Bruno Oliveira
ba8b3be61a Improve CHANGELOG 2019-01-09 20:27:18 -02:00
Yoav Caspi
2467831913 rephrase warning section to explain better the issue. 2019-01-09 23:52:08 +02:00
Bruno Oliveira
e4a21b11d5 Change test_warningschecker_twice to a unittest 2019-01-09 18:58:51 -02:00
Daniel Hahler
f3b6425324 Merge pull request #4620 from Sup3rGeo/bugfix/warningschecker-twice
Bugfix/warningschecker twice
2019-01-09 15:36:29 +01:00
Daniel Hahler
7ee03e0996 Punctuation [ci skip] 2019-01-09 15:35:52 +01:00
Victor Maryama
081accb62c Fixed linting in changelog. 2019-01-09 13:11:22 +01:00
Victor Maryama
fe4835c15e Added changelog entry. 2019-01-09 12:55:15 +01:00
Victor Maryama
df3b5557d1 Reseting entered state in WarningsRecorder (fixes 4617) 2019-01-09 12:51:04 +01:00
Victor Maryama
948a5d5ac6 Added test for Issue 4617 2019-01-09 12:31:26 +01:00
Oscar Benjamin
85055a9efe Show full repr with assert a==b and -vv 2019-01-08 01:25:05 +00:00
Yoav Caspi
149620f858 update changelog 2019-01-06 23:11:27 +02:00
Yoav Caspi
6ee5d431a0 add warning for using non canonical configuration files. 2019-01-06 23:11:24 +02:00
Anthony Sottile
a4c426b1a8 Merge pull request #4604 from asottile/uninstall_hypothesis
Uninstall hypothesis in regen tox env
2019-01-06 10:28:11 -08:00
Anthony Sottile
4f38c610c3 Uninstall hypothesis in regen tox env 2019-01-06 07:53:39 -08:00
Bruno Oliveira
38adb23bd2 Merge pull request #4600 from nicoddemus/release-4.1.0
Release 4.1.0
2019-01-06 13:09:11 -02:00
Bruno Oliveira
e24031fb36 Regendocs again, without hypothesis 2019-01-05 20:42:44 +00:00
Bruno Oliveira
99ef8c6d16 Fix typo in Makefile: PYTEST_ADDOPT -> PYTEST_ADDOPTS 2019-01-05 20:31:01 +00:00
Bruno Oliveira
e8152207c4 Merge pull request #4601 from Stranger6667/fix-typo
Fix typo in the Changelog for `get_closest_marker`
2019-01-05 18:25:50 -02:00
Bruno Oliveira
d7465895d0 Regendoc again 2019-01-05 19:19:40 +00:00
dmitry.dygalo
5d0bcb4419 Fix typo in the Changelog for get_closest_marker 2019-01-05 20:08:09 +01:00
Bruno Oliveira
01151ff566 Add example for -ra usage to the docs 2019-01-05 16:53:12 -02:00
Bruno Oliveira
d0e9b4812f Regendocs 2019-01-05 16:38:59 -02:00
Bruno Oliveira
5a8e674e92 Add dataclasses as a regendoc dependency 2019-01-05 16:38:59 -02:00
Bruno Oliveira
e380d4306b Anonimize attrs links 2019-01-05 16:38:59 -02:00
Bruno Oliveira
9d297c06e8 Preparing release version 4.1.0 2019-01-05 16:38:59 -02:00
Anthony Sottile
e24fdb138d Merge pull request #4598 from nicoddemus/license-year
Update copyright year
2019-01-05 09:09:55 -08:00
Bruno Oliveira
0da5531c7c Merge pull request #4599 from s0undt3ch/feature/skiporfail-reason
Custom reason support for "importorskip"
2019-01-05 13:15:17 -02:00
Bruno Oliveira
0c4898670c Add changelog entry and update docs for importorskip 2019-01-05 12:55:39 -02:00
Pedro Algarvio
be7eb22e88 Add test case for importorskip custom reason 2019-01-04 19:06:23 +00:00
Pedro Algarvio
8b48621687 Allow providing a custom reason for importorskip 2019-01-04 18:05:28 +00:00
Anthony Sottile
56aecfc081 Merge pull request #4587 from nicoddemus/merge-master-into-features
Merge master into features
2019-01-04 09:57:08 -08:00
Anthony Sottile
82a0308bc6 Merge pull request #4595 from auscompgeek/patch-1
Fix PEP 565 typo in warnings.rst
2019-01-04 09:56:23 -08:00
Bruno Oliveira
7f671586b0 Update copyright year 2019-01-04 10:37:07 -02:00
David Vo
9e62f9d64e Fix PEP 565 typo in warnings.rst 2019-01-04 11:50:36 +11:00
Bruno Oliveira
81c2780d2b Move Node.get_marker and markname deprecations next to the other 4.0 ones 2019-01-02 19:37:17 -02:00
Bruno Oliveira
b39b69a730 Use sphinx-removed-in extension in the documentation
Fix #4568
2019-01-02 19:34:46 -02:00
Bruno Oliveira
30c7a7bd69 Merge remote-tracking branch 'upstream/master' into features 2019-01-02 19:16:18 -02:00
Bruno Oliveira
cf5a9aebb2 Merge pull request #4580 from adamchainz/improve_detailed_summary_report_docs
Improve detailed summary report docs
2019-01-01 16:28:27 -02:00
Bruno Oliveira
1a9979a803 Merge pull request #4582 from jeffreyrack/4371-display-test-descriptions
4371: Update --collect-only to display test descriptions when ran in verbose
2018-12-30 13:56:30 -02:00
Jeffrey Rackauckas
1eef53b6fe Update --collect-only to display test descriptions when ran in verbose mode. 2018-12-29 22:46:46 -08:00
Adam Johnson
388aff16c8 Improve detailed summary report docs
The existing examples had 0 tests collected so didn't show the actual summary report. Also I added a section explaining the difference between `p` and `P`.
2018-12-29 11:47:39 +00:00
wim glenn
83ec0228d1 Merge pull request #4577 from pytest-dev/asottile-patch-1
Remove out of date dependencies list in docs
2018-12-27 00:02:42 -06:00
Anthony Sottile
2dc8cc1e48 Remove out of date dependencies list in docs
Was scrolling through the docs and noticed this, I figure it's easier to remove this than try and keep it in sync with setup.py
2018-12-25 20:46:48 -05:00
Anthony Sottile
658fa35642 Merge pull request #4572 from bowlofeggs/rm-comma
Remove an extraneous comma from the docs.
2018-12-22 23:13:45 -05:00
Randy Barlow
b2c4ed9a2b Remove an extraneous comma from the docs.
Signed-off-by: Randy Barlow <randy@electronsweatshop.com>
2018-12-21 17:53:28 -05:00
Bruno Oliveira
b5cd43bc95 Merge pull request #4558 from hyunchel/fix-incorrect-example-in-cache-doc
Update cache doc with correct example
2018-12-21 14:33:41 -02:00
Bruno Oliveira
134ace98d9 Merge pull request #4564 from RonnyPfannschmidt/remove-markinfo
Remove MarkInfo
2018-12-21 14:32:15 -02:00
Ronny Pfannschmidt
134641fcb5 add first set of changelog entries for marker removal 2018-12-21 14:02:38 +01:00
Ronny Pfannschmidt
8f8d3114dd apply suggested enhancements in deprecations.rst 2018-12-21 14:02:38 +01:00
Ronny Pfannschmidt
102ffc69e8 add issue references to the todos 2018-12-21 14:02:38 +01:00
Ronny Pfannschmidt
64a353f2b6 update deprecation docs 2018-12-21 14:02:38 +01:00
Ronny Pfannschmidt
b258764ffe fix docs 2018-12-21 14:02:38 +01:00
Ronny Pfannschmidt
3947b859dc fix hookspec parsing 2018-12-21 14:02:38 +01:00
Ronny Pfannschmidt
9f9f6ee48b remove most of markertransfer
keywords are still a big issue
2018-12-21 14:02:38 +01:00
Bruno Oliveira
58fc918d0a Merge pull request #4571 from nicoddemus/remove-parametrize-marks
Remove support for applying marks to values in parametrize
2018-12-21 08:24:47 -02:00
Hyunchel Kim
ece01b0f56 Update cache documentation example to correctly show cache hit and miss 2018-12-21 04:43:26 +00:00
Bruno Oliveira
c378cb4793 Remove support for applying marks to values in parametrize
Fix #3082
2018-12-20 16:16:13 -02:00
Ronny Pfannschmidt
d888d5c933 Merge pull request #4565 from nicoddemus/flaky-test
Use mocking to make test_junit_duration_report deterministic
2018-12-20 08:52:34 +01:00
Ronny Pfannschmidt
b2d3ae257a Merge pull request #4566 from nicoddemus/remove-setup-cfg-non-top-level-pytest-plugins
Remove support for [pytest] in setup.cfg files and pytest_plugins in non-top-level conftests
2018-12-20 08:47:25 +01:00
Bruno Oliveira
a93f41233a Raise an error if pytest_plugins is defined in a non-top-level conftest.py file
Fix #4548
2018-12-19 18:09:47 -02:00
Bruno Oliveira
9138419379 Remove support for '[pytest]' section in setup.cfg file
Fix #3086
2018-12-19 17:43:17 -02:00
Bruno Oliveira
197fd69ddc Use mocking to make test_junit_duration_report deterministic
Fix #4563
2018-12-19 17:13:12 -02:00
Bruno Oliveira
c400d8b2d8 Merge pull request #4561 from nicoddemus/remove-calling-fixtures-directly
Calling fixtures directly is now an error instead of a warning
2018-12-19 11:37:14 -02:00
Bruno Oliveira
0115766df3 Calling fixtures directly is now an error instead of a warning
Fix #4545
2018-12-19 09:26:29 -02:00
Bruno Oliveira
8563364d8b Merge pull request #4542 from nicoddemus/remove-legacy-warn
Remove config.warn, Node.warn and pytest_logwarning
2018-12-18 19:11:36 -02:00
Bruno Oliveira
0a40ae4c6a Merge pull request #4557 from Kanguros/master
Updating markers example to newest pytest version
2018-12-17 12:45:27 -02:00
Ronny Pfannschmidt
e63c7a13ff Merge pull request #4327 from ndevenish/approx
Let approx() work on more generic sequences
2018-12-17 15:21:12 +01:00
Bruno Oliveira
b7e8171cf8 Merge branch 'features' into remove-legacy-warn 2018-12-17 10:37:31 -02:00
Bruno Oliveira
75e93e5168 Merge pull request #4556 from nicoddemus/idfunc-failure
Errors in parametrize id functions now propagate the error instead of issuing a warning
2018-12-17 10:36:15 -02:00
Bruno Oliveira
843d00c219 Fix linting 2018-12-17 10:35:17 -02:00
Bruno Oliveira
c6d27d8224 Merge pull request #4555 from nicoddemus/remove-record-xml-pytest-main-str
Remove record_xml_property and support for strings in pytest.main()
2018-12-17 10:08:51 -02:00
Bruno Oliveira
84390acccc Merge pull request #4553 from nicoddemus/junit-durations
Rename "junit_time" to "junit_duration_report" option
2018-12-17 10:08:20 -02:00
Kanguros
f04d3c8b7d Adding change log entry 2018-12-16 21:27:59 +01:00
Kanguros
60773e0a97 Updating markers example to newest pytest version 2018-12-16 21:13:14 +01:00
Daniel Hahler
3cf44b3037 Merge pull request #4554 from blueyed/merge-master
Merge master into features
2018-12-15 02:44:38 +01:00
Bruno Oliveira
1499778d5e Errors in parametrize id functions now propagate the error instead of issuing a warning
Fix #2169
2018-12-14 21:07:54 -02:00
Bruno Oliveira
a7e401656e Remove support to pass strings to pytest.main()
Fix #3085
2018-12-14 15:45:47 -02:00
Bruno Oliveira
6e1b1abfa7 Remove deprecated record_xml_property
Fix #4547
2018-12-14 15:10:08 -02:00
Daniel Hahler
8e287c5c77 Merge master into features 2018-12-14 16:44:43 +01:00
Bruno Oliveira
231863b133 Rename "junit_time" to "junit_duration_report" option
Just realized while reading the changelog that "junit_time" is not a very good
name, so I decided to open this PR renaming it to "junit_duration_report" which
I believe conveys the meaning of the option better
2018-12-14 12:56:26 -02:00
Bruno Oliveira
ae5d5b8f59 Merge pull request #4552 from nicoddemus/review-changelog-entries
Review changelog entries for features branch
2018-12-14 12:52:55 -02:00
Bruno Oliveira
fd48cd57f9 Remove config.warn, Node.warn; pytest_logwarning issues a warning when implemented
Fix #3078
2018-12-14 12:50:18 -02:00
Bruno Oliveira
98987177a0 Review changelog entries for features branch
I used `towncrier --draft` to see the full changelog, and decided to "nitpick" it
so it reads better as a whole.
2018-12-14 11:17:24 -02:00
Bruno Oliveira
437f44a1f4 Merge pull request #4544 from nicoddemus/remove-pytest-funcarg-prefix
Remove pytest_funcarg__ prefix support for defining fixtures
2018-12-14 08:36:09 -02:00
Bruno Oliveira
b76104e722 Merge pull request #4550 from nicoddemus/release-4.0.2
Release version 4.0.2
2018-12-14 08:28:18 -02:00
Bruno Oliveira
1e80a9cb34 Remove pytest_funcarg__ prefix support for defining fixtures
Fix #4543
2018-12-13 21:41:38 -02:00
Bruno Oliveira
6c5a1150d4 Preparing release version 4.0.2 2018-12-13 23:37:51 +00:00
Bruno Oliveira
26d202a7bd Merge pull request #4529 from aparamon/jxmlunit-call-time
Add --junittime=call option
2018-12-13 13:51:06 -02:00
Bruno Oliveira
b390c66dc4 Merge pull request #4292 from blueyed/exit-outcome
Derive outcomes.exit.Exit from SystemExit instead of KeyboardInterrupt
2018-12-13 13:43:39 -02:00
Bruno Oliveira
f96e1b6f3e Merge pull request #4532 from nicoddemus/failure-summary
Change -ra to show errors and failures last, instead of first
2018-12-13 10:30:28 -02:00
Bruno Oliveira
e03c1f538f Merge pull request #4540 from asottile/type_error_falsey_match_value
Raise `TypeError` for `with raises(..., match=<non-None falsey value>)`.
2018-12-13 06:01:44 -02:00
Bruno Oliveira
15b0a89fb1 Merge pull request #4539 from nicoddemus/deprecate-pytest-raises-message
Deprecate the 'message' parameter of pytest.raises
2018-12-13 06:00:59 -02:00
Bruno Oliveira
5b83417afc Deprecate the 'message' parameter of pytest.raises
Fix #3974
2018-12-12 22:26:30 -02:00
Anthony Sottile
a254ad0436 Raise TypeError for with raises(..., match=<non-None falsey value>). 2018-12-12 14:59:22 -08:00
Daniel Hahler
9b3be870dc Improve comment 2018-12-12 23:29:43 +01:00
Daniel Hahler
7a600ea3eb Improve changelog 2018-12-12 23:28:47 +01:00
Bruno Oliveira
110fe2473f Merge pull request #4531 from nicoddemus/remove-custom-collection-types
Remove PyCollector.makeitem
2018-12-12 18:27:50 -02:00
Christopher Dignam
f8d31d2400 Bugfix: monkeypatch.delattr handles class descriptors
Correct monkeypatch.delattr to match the correct behavior of
monkeypatch.setattr when changing class descriptors
2018-12-12 15:20:24 -05:00
Daniel Hahler
6af674a3ac Merge pull request #4520 from blueyed/PYTEST_DISABLE_PLUGIN_AUTOLOAD-del
tests: fix tests that require PYTEST_DISABLE_PLUGIN_AUTOLOAD to be unset
2018-12-12 18:40:46 +01:00
Bruno Oliveira
e3d30f8ebf Remove deprecated PyCollector.makeitem
Fix #4535
2018-12-12 14:15:52 -02:00
Andrey Paramonov
5d79baf3f8 Fix flaky test attempt 2 2018-12-12 15:33:29 +03:00
Andrey Paramonov
ec4507d12a Fix doc formatting 2018-12-12 14:33:02 +03:00
Andrey Paramonov
b1e766c30e Update docs 2018-12-12 13:27:44 +03:00
Andrey Paramonov
316cca204f Switch to ini config parameter 2018-12-12 13:19:39 +03:00
Andrey Paramonov
0bccfc44a7 Fix flaky test 2018-12-12 12:14:14 +03:00
Bruno Oliveira
3cd11617ea Add CHANGELOG 2018-12-11 20:40:06 -02:00
Bruno Oliveira
9839ceffe0 Change -ra to show errors and failures last, instead of first
Often in large test suites (like pytest's), the -ra summary is very useful
to obtain a list of failures so we can execute each test at once to fix them.

Problem is the default shows errors and failures first, which leads to a lot
of scrolling to get to them.
2018-12-11 20:36:57 -02:00
Bruno Oliveira
a44776ed48 Fix linting 2018-12-11 15:16:11 -02:00
Andrey Paramonov
cfbd387a5d Add --junittime=call option 2018-12-11 19:29:31 +03:00
Daniel Hahler
bb363c8ff2 Merge pull request #4528 from blueyed/parser-prog
argparsing: Parser: allow to forward prog to argparse
2018-12-11 13:33:40 +01:00
Daniel Hahler
ebe0a88226 Merge pull request #4522 from blueyed/p-no-space
Handle missing space with -p
2018-12-11 13:33:18 +01:00
Daniel Hahler
3445eae737 argparsing: Parser: allow to forward prog to argparse
Ref: https://github.com/pytest-dev/pytest-xdist/pull/388.
2018-12-11 06:22:35 +01:00
Daniel Hahler
8152b6837e Merge pull request #4419 from blueyed/set_trace-kwargs
pdb: support kwargs with `pdb.set_trace`
2018-12-11 04:28:24 +01:00
Daniel Hahler
0e4e8e00a9 Merge pull request #4504 from feuillemorte/4278_add_cachedir_tag
#4278 Added a CACHEDIR.TAG file to the cache directory
2018-12-11 04:27:35 +01:00
Daniel Hahler
7b1cb885c7 Handle missing space with -p
This still does not use an actual argument parser, which only gets
instantiated below, and it does not appear to make sense instantiating
it just for this pre-parsing it seems.

`-p` without the required value is being handled before already though,
so it could potentially be passed down from somewhere already?!

Fixes https://github.com/pytest-dev/pytest/issues/3532.
2018-12-11 04:27:03 +01:00
Daniel Hahler
fc4aa27cae Derive outcomes.exit.Exception from SystemExit instead of KeyboardInterrupt
This is required for properly getting out of pdb, where
KeyboardInterrupt is caught in py36 at least.

Ref: https://github.com/pytest-dev/pytest/issues/1865#issuecomment-242599949
2018-12-11 04:22:33 +01:00
Bruno Oliveira
22345ef722 Merge pull request #4525 from blueyed/fix-test_raises_exception_looks_iterable
tests: fix test_raises_exception_looks_iterable
2018-12-10 15:29:18 -02:00
Daniel Hahler
038f1f94c2 Merge pull request #4524 from blueyed/merge-master
Merge master into features
2018-12-10 10:17:23 +01:00
Daniel Hahler
539d3dc34d Merge branch 'fix-test_raises_exception_looks_iterable' into merge-master 2018-12-10 06:30:36 +01:00
Daniel Hahler
5ecbb02ace tests: fix test_raises_exception_looks_iterable
Started to fail on py37-xdist between
https://travis-ci.org/pytest-dev/pytest/jobs/465498973 and
https://travis-ci.org/pytest-dev/pytest/jobs/465792343, but could not
find a diff in versions (from the tox header), and both commits failed
locally.
2018-12-10 06:26:32 +01:00
Daniel Hahler
0db5ccb0dd Merge master into features 2018-12-10 05:42:07 +01:00
Daniel Hahler
abb0dfcfa3 Merge pull request #4523 from blueyed/addopts-separate
Ensure that PYTEST_ADDOPTS and addopts ini values are valid by themselves.
2018-12-10 01:43:04 +01:00
Daniel Hahler
f3babf13ea Ensure that PYTEST_ADDOPTS are valid by themselves
Fixes https://github.com/pytest-dev/pytest/issues/4265.
2018-12-09 21:57:10 +01:00
Daniel Hahler
64ee1ee81b tests: fix tests that require PYTEST_DISABLE_PLUGIN_AUTOLOAD to be unset
Fix pytest's own tests with PYTEST_DISABLE_PLUGIN_AUTOLOAD=1.
2018-12-09 12:06:18 +01:00
Bruno Oliveira
76884c73bf Merge pull request #4146 from Tadaboody/give_hints_when_an_assertion_value_is_None_instead_of_a_boolean_3191
[#3191] Give hints when an assertion value is None instead of a boolean
2018-12-05 20:04:52 -02:00
Daniel Hahler
5ebacc49c6 Harden tests, fix doc/msg 2018-12-05 19:22:44 +01:00
Daniel Hahler
8a0ed7e2b3 Revisit changelog entry [ci skip] 2018-12-05 19:14:41 +01:00
Daniel Hahler
62b8f2f731 Update changelog [ci skip] 2018-12-05 19:07:10 +01:00
Tomer Keren
8fd60483ef Don't insert warnings when not in a module 2018-12-05 19:49:54 +02:00
Tomer Keren
7a7ad0c120 Shorten docstring for warn_about_none_ast 2018-12-05 17:47:34 +02:00
Tomer Keren
41031fce2f Address code review 2018-12-05 17:18:57 +02:00
Ronny Pfannschmidt
818aa4d343 Merge pull request #4509 from Tadaboody/doc_doctest_fixture_pitfall_1495
Document doctest fixture pitfalls
2018-12-05 15:40:45 +01:00
Tomer Keren
b7a64d6729 Create changelog file for 1495 2018-12-05 11:29:32 +02:00
Tomer Keren
cb52d17d07 Document doctest fixture pitfalls 2018-12-05 11:25:52 +02:00
Tomer Keren
e1e4b226c6 👌 Address code review
Edited the changelog for extra clarity, and to fire off auto-formatting

Oddly enough, keeping `filename='{filename!r}'` caused an error while
collecting tests, but getting rid of the single ticks fixed it
Hopefully closes #3191
2018-12-05 10:52:12 +02:00
Bruno Oliveira
26d27df6fc Improve changelog message 2018-12-05 10:41:30 +02:00
Tomer Keren
3e6f1fa2db Simplify warning creation by using ast.parse
in py2 it's a ast.Name where in py3 it's a ast.NamedConstant

Fixes namespace by using import from
2018-12-05 10:42:05 +02:00
Tomer Keren
aaf7f7fcca Update changelog 2018-12-05 10:41:30 +02:00
Tomer Keren
e0c2ab1901 Fix tests not to assert a function that already asserts
Maybe there should be a warning about that too?
2018-12-05 10:41:30 +02:00
Tomer Keren
59a11b6a5d Check for 'assert None' and warn appropriately
:bug:Fix warn ast bugs

:bug:Fix inner-ast imports by using importFrom

Alternetavly ast_call_helper could be retooled to use ast.attribute(...)
2018-12-05 10:41:42 +02:00
Tomer Keren
9fc9b2926f Fix tests and add aditional cases
As requested by review.

👌 Address code review for tests
2018-12-05 10:41:30 +02:00
Tomer Keren
1654b77ca0 [#3191] Set up tests to confirm warnings 2018-12-05 10:41:18 +02:00
Bruno Oliveira
60599b667e Merge pull request #4505 from yashtodi94/patch-1
Rectified typo
2018-12-04 12:23:31 -02:00
Yash Todi
db32949c50 Rectified typo 2018-12-04 19:33:13 +05:30
feuillemorte
d237197de3 #4278 Added a CACHEDIR.TAG file to the cache directory 2018-12-04 13:49:08 +01:00
Ronny Pfannschmidt
86ccfaec22 Merge pull request #4503 from asottile/upgrade
Upgrade sphinx doc requirements
2018-12-04 07:49:07 +01:00
Anthony Sottile
ae92b8c624 Upgrade sphinx doc requirements 2018-12-03 15:30:45 -08:00
Anthony Sottile
5db46d2087 Merge pull request #4498 from asottile/deprecate_pytest_config
Deprecate pytest.config
2018-12-03 11:10:15 -08:00
Anthony Sottile
99d3fe22dc Merge pull request #4501 from s0undt3ch/master
Test case for #4500 and respective fix #4487
2018-12-03 09:11:00 -08:00
Anthony Sottile
b88c3f8f82 Deprecate pytest.config 2018-12-03 09:01:42 -08:00
Pedro Algarvio
6da8befc74 Black suggestions 2018-12-03 12:58:22 +00:00
Pedro Algarvio
c1bdb07b2f Fix change log entry 2018-12-03 12:17:14 +00:00
Pedro Algarvio
14024c7fc1 Test case for #4500 bug and respective fix #4487 2018-12-03 12:17:14 +00:00
Pedro Algarvio
517b8bc69e Stop using the deprecated \.warn() log handler method 2018-12-03 11:52:33 +00:00
Daniel Hahler
ecc5c84c1e Merge pull request #4487 from s0undt3ch/master
Logging done late enough might happen when capture already stopped.
2018-12-02 12:10:00 +01:00
Anthony Sottile
4a3c8e22d7 Merge pull request #4491 from nicoddemus/removal-links
Add links to the deprecations docs for the "removal" changelog entries
2018-12-01 21:05:32 -08:00
Pedro Algarvio
f792cc420c Add changelog entry 2018-12-01 21:40:11 +00:00
Pedro Algarvio
f4d3ec6370 Logging done late enough might happen when capture already stopped. 2018-12-01 21:40:11 +00:00
Bruno Oliveira
a131f0acf6 Merge pull request #4490 from nicoddemus/remove-cached-setup-add-call
Remove cached_setup and Metafunc.addcall
2018-12-01 18:44:51 -02:00
Bruno Oliveira
4ffa13728d Add links to the deprecations docs for the "removal" changelog entries 2018-12-01 17:33:48 -02:00
Bruno Oliveira
44b74c8c25 Merge pull request #4447 from nicoddemus/remove-result-log
Change resultlog deprecation to PytestDeprecatedWarning
2018-12-01 17:26:17 -02:00
Bruno Oliveira
40b85d7ee8 Remove Metafunc.addcall
Fix #3083
2018-12-01 16:41:59 -02:00
Bruno Oliveira
090f7ff449 Remove request.cached_setup
Fix #4489
2018-12-01 15:59:44 -02:00
Bruno Oliveira
b05061dcd2 Change deprecation type of --result-log to PytestDeprecationWarning
It was decided to deprecate this on a later date (see discussion in #4447)
2018-12-01 14:29:50 -02:00
Bruno Oliveira
06dc6e3490 Merge pull request #4446 from nicoddemus/update-deprecations-docs
Update deprecations.rst now that we have removed a few features
2018-12-01 14:22:19 -02:00
Bruno Oliveira
63f38de38e Merge remote-tracking branch 'upstream/features' into update-deprecations-docs 2018-12-01 14:16:20 -02:00
Bruno Oliveira
e0ba1cbf8d Merge pull request #4299 from RonnyPfannschmidt/callinfo-sanity
refactor callinfo to simplify ctor magic
2018-11-30 14:07:40 -02:00
Ronny Pfannschmidt
847eacea19 refactor CallInfo constructor magic into named constructor 2018-11-30 13:21:54 +01:00
Ronny Pfannschmidt
b531f7d585 Merge pull request #3898 from RonnyPfannschmidt/remove-yield-and-compatprop
Remove yield and compatprop
2018-11-30 13:19:23 +01:00
Ronny Pfannschmidt
7eb28f9eb7 remove yield tests and compat properties 2018-11-30 10:40:13 +01:00
Anthony Sottile
1d86247b2c Merge pull request #4443 from asottile/deprecate_raises_exec
Deprecate `raises(..., 'code(as_a_string)')` / `warns(..., 'code(as_a_string)')`.
2018-11-29 11:57:56 -08:00
Anthony Sottile
1bba0a9714 Deprecate raises(..., 'code(as_a_string)') / `warns(..., 'code(as_a_string)') 2018-11-29 09:34:51 -08:00
Bruno Oliveira
5cf69fae7d Merge pull request #4466 from nicoddemus/merge-master-into-features
Merge master into features
2018-11-27 05:37:15 -02:00
Bruno Oliveira
b73e083d9d Merge remote-tracking branch 'upstream/master' into merge-master-into-features 2018-11-26 12:55:05 -02:00
Bruno Oliveira
d8e00c983e Merge pull request #4465 from nicoddemus/appveyor-retry
[skip travis] Use retry script on AppVeyor
2018-11-26 12:54:02 -02:00
Bruno Oliveira
b00b715cb6 [skip travis] Use retry script on AppVeyor
Fix #4387
2018-11-26 11:35:34 -02:00
Anthony Sottile
7d3ca68be6 Merge pull request #4464 from asottile/dash_q_escaped
Display actual test ids in `--collect-only`
2018-11-25 11:30:26 -08:00
Anthony Sottile
e9b2475e29 Display actual test ids in --collect-only 2018-11-25 09:33:18 -08:00
Bruno Oliveira
d05b30ce11 Merge pull request #4462 from asottile/bump_pygments_pytest
Bump pygments-pytest
2018-11-25 00:01:06 -02:00
Anthony Sottile
2eac1bfcb8 Bump pygments-pytest 2018-11-24 17:25:53 -08:00
Bruno Oliveira
91b25c4dec Merge pull request #4461 from asottile/fix_rtd
Fix rtd by installing pygments-pytest
2018-11-24 21:24:52 -02:00
Anthony Sottile
d219e033e9 Fix rtd by installing pygments-pytest 2018-11-24 14:48:12 -08:00
Ronny Pfannschmidt
59f65230b5 Merge pull request #4454 from nicoddemus/merge-master-into-features
Merge master into features
2018-11-24 16:34:20 +01:00
Anthony Sottile
3d8d04c6f8 Merge pull request #4456 from asottile/pygments_pytest
Highlight docs with pygments-pytest
2018-11-24 07:32:51 -08:00
Daniel Hahler
5bee396e4b Merge master into merge-master-into-features 2018-11-24 13:47:10 +01:00
Bruno Oliveira
8facf1db90 Merge pull request #4457 from nicoddemus/test-request-garbage
Try to fix/improve reporting of test_request_garbage
2018-11-24 10:08:44 -02:00
Bruno Oliveira
9e522c97fa Try to fix/improve reporting of test_request_garbage
* Run it in a subprocess to reduce possible intereference from the outer pytest
* Print the leaked objects to see if they provide any hints
2018-11-24 08:29:39 -02:00
Anthony Sottile
7015801377 Highlight docs with pygments-pytest 2018-11-23 22:01:30 -08:00
Anthony Sottile
860bc50772 Merge pull request #4451 from asottile/report_correct_filename_raises_exec
Fix `raises(..., "code(string)")` frame filename.
2018-11-23 17:29:09 -08:00
Bruno Oliveira
33b877cc01 Merge remote-tracking branch 'upstream/master' into merge-master-into-features 2018-11-23 23:27:41 -02:00
Bruno Oliveira
f75f2117d0 Merge pull request #4450 from nicoddemus/release-4.0.1
Release version 4.0.1
2018-11-23 23:21:49 -02:00
Anthony Sottile
0d5298475d Fix raises(..., "code(string)") frame filename. 2018-11-23 15:01:35 -08:00
Daniel Hahler
be3b8fc9c1 Fix warnings summary header appearing twice
Ref: https://github.com/pytest-dev/pytest/pull/4450#discussion_r236017645
Ref: https://github.com/pytest-dev/pytest/pull/4399
2018-11-23 22:47:58 +01:00
Bruno Oliveira
16b15af624 Preparing release version 4.0.1 2018-11-23 20:09:57 +00:00
Bruno Oliveira
23e4447922 Merge pull request #4399 from blueyed/summary
Display "short test summary info" after (main) warnings again
2018-11-23 18:06:40 -02:00
Daniel Hahler
0cf45ee18a Display "short test summary info" after (main) warnings again
Fixes https://github.com/pytest-dev/pytest/issues/3952.
2018-11-23 20:06:09 +01:00
Bruno Oliveira
63f90a2bcd Merge pull request #4438 from RonnyPfannschmidt/fix-4386-raises-partial-object
fix #4386 - restructure construction and partial state of ExceptionInfo
2018-11-23 12:41:14 -02:00
Bruno Oliveira
0b73d6d4f5 Merge pull request #4444 from RonnyPfannschmidt/fix-4386-2
fix #4386 - handle uninitialized exceptioninfo in repr/str
2018-11-23 12:40:41 -02:00
Bruno Oliveira
e4ae33d592 Merge pull request #4394 from blueyed/cache-ensure-files
cacheprovider: do not write README/.gitignore to existing dir
2018-11-23 09:07:49 -02:00
Bruno Oliveira
c5c728c8bc Fix test/improve tests a bit in py27 2018-11-22 21:38:33 -02:00
Bruno Oliveira
f987b368e8 Merge pull request #3776 from alysivji/attrs-n-dataclasses
Detailed assert failure introspection for attrs and dataclasses objects
2018-11-22 21:25:35 -02:00
Bruno Oliveira
5d2e2377ff Update deprecations.rst now that we have removed a few features
* yield tests
* compat properties
* pytest_namespace

All merciless cut down by Ronny :'(
2018-11-22 20:38:47 -02:00
Bruno Oliveira
9ae8429a21 Use a more specific exception type in test_raises_repr_inflight
As requested during review
2018-11-22 20:24:46 -02:00
Bruno Oliveira
2eaf3db6ae Fix docstring indentation (docs env) 2018-11-22 20:21:22 -02:00
Ronny Pfannschmidt
88bf01a31e fix #4386 - restructure construction and partial state of ExceptionInfo 2018-11-22 21:20:32 +01:00
Ronny Pfannschmidt
abaf496fe8 Merge pull request #4440 from nicoddemus/config-warning-stacklevel
Adjust stacklevel of "config" warnings
2018-11-22 21:02:52 +01:00
Ronny Pfannschmidt
b71bd9b300 fix #4386 - handle uninitialized exceptioninfo in repr/str 2018-11-22 20:52:15 +01:00
Ronny Pfannschmidt
94d032a6de Merge pull request #4436 from asottile/print_function
Fix formatting of print() calls
2018-11-22 20:17:19 +01:00
Bruno Oliveira
9424d88843 Merge pull request #4427 from RonnyPfannschmidt/fix-4425
fix 4425: resolve --basetemp to absolute paths
2018-11-22 17:10:10 -02:00
Bruno Oliveira
d471ecc4d8 Add changelog entry 2018-11-22 14:45:50 -02:00
Bruno Oliveira
aa765cf8c2 Adjust stacklevel of "config" warnings
Related to #4439
2018-11-22 14:44:01 -02:00
Ronny Pfannschmidt
5f1d692072 use Path.resolve in test to sort out osx temporary folder being a symlink 2018-11-22 16:10:12 +01:00
Ronny Pfannschmidt
2c45bc3019 Merge pull request #4437 from asottile/consistency_errors_red
Color the setup ERROR red
2018-11-22 12:00:07 +01:00
Anthony Sottile
664257c7a3 Color the setup ERROR red 2018-11-22 00:20:13 -08:00
Anthony Sottile
b3700f61ba Fix formatting of print() calls 2018-11-22 00:15:14 -08:00
Ronny Pfannschmidt
d894bf4535 Merge pull request #4407 from blueyed/sys-dunder
capture: do not overwrite `sys.__stdin__` etc
2018-11-22 07:26:06 +01:00
Bruno Oliveira
3eaa6d8835 Merge pull request #4433 from 3lnc/doc_explicit_multimarker
Adds note on multiple module marker usage
2018-11-21 20:51:29 -02:00
Bruno Oliveira
f1fe9e41ac Mention PR# in the comment for future reference 2018-11-21 20:49:17 -02:00
Bruno Oliveira
4f5c153d29 Fix call to os.path.abspath: the argument might already be a Path instance
There's Path.absolute(), but it is not public, see https://bugs.python.org/issue25012.
2018-11-21 20:46:08 -02:00
Slam
ee4f8c98a9 Adds note on multiple module marker usage 2018-11-21 14:37:28 +02:00
Bruno Oliveira
f180ab3e69 Use os.path.abspath to get absolute path instead of Path.resolve()
Unfortunately it seems there is a difference in resolve() behavior depending
on the platform
2018-11-20 20:08:01 -02:00
Daniel Hahler
9ed63c607e capture: do not overwrite sys.__stdin__ etc
Ref: https://github.com/pytest-dev/pytest/pull/4398#discussion_r234333053
2018-11-20 16:50:15 +01:00
Ronny Pfannschmidt
fc61bdd907 fix 4425: resolve --basetemp to absolute paths 2018-11-20 16:14:50 +01:00
Bruno Oliveira
d52ea4b6cf Use python 3 in 'doctesting' environment
We some examples now use type annotations
2018-11-19 20:06:06 -02:00
Ronny Pfannschmidt
0ffb8ddd7f Merge pull request #4418 from asottile/printable_ids
Ensure that node ids are printable
2018-11-19 21:40:07 +01:00
Ronny Pfannschmidt
45c33c4e05 Merge pull request #4379 from hoylemd/improve_minversion_again
Use packaging/pkg_resources to check minversion
2018-11-19 21:38:45 +01:00
Anthony Sottile
95c6d591f7 Properly escape \r \n \t bytes 2018-11-19 11:03:52 -08:00
Anthony Sottile
9a1e518cc3 Add changelog entry for printable node ids 2018-11-19 11:03:52 -08:00
Anthony Sottile
9ca0ab6e2b Ensure printable manually-specified param(id=...) 2018-11-19 11:03:52 -08:00
Anthony Sottile
8395b9e25d Require id=... to be a string
This was documented before, but never enforced.  Passing non-strings could
have strange side-effects and enforcing a string simplifies other
implementation.
2018-11-19 11:03:52 -08:00
Anthony Sottile
3d92d5a659 Make sure parametrize ids are printable 2018-11-19 11:03:52 -08:00
Anthony Sottile
50e3783f07 Merge pull request #4421 from RonnyPfannschmidt/remove-pytest-namespace
remove pytest namespace hook
2018-11-19 09:35:33 -08:00
Michael D. Hoyle
1568e38997 Use pkg_resources.parse_version in minver check
Use pkg_resources.parse_version in minver check

Add meself to AUTHORS & changelog

Format CHANGELOG
2018-11-19 11:25:27 -05:00
Daniel Hahler
6e85febf20 Merge pull request #4420 from blueyed/merge-master
Merge master into features
2018-11-19 14:53:01 +01:00
Ronny Pfannschmidt
ba17363d75 remove pytest namespace hook 2018-11-19 14:04:41 +01:00
Daniel Hahler
92a2884b09 pdb: support kwargs with pdb.set_trace
This handles `header` similar to Python 3.7 does it, and forwards any
other keyword arguments to the Pdb constructor.

This allows for `__import__("pdb").set_trace(skip=["foo.*"])`.

Fixes https://github.com/pytest-dev/pytest/issues/4416.
2018-11-19 13:04:14 +01:00
Daniel Hahler
2754a13f86 Merge master into features 2018-11-19 12:55:29 +01:00
Anthony Sottile
a281d6620b Merge pull request #4417 from blueyed/tox-mock
tox.ini: remove additionally missed mock deps
2018-11-18 12:06:59 -08:00
Nicholas Devenish
4eddf634e7 Rename and split out the testing, and reword the changelog. 2018-11-18 20:01:11 +00:00
Nicholas Devenish
1a8d9bf254 Let approx() work on more generic sequences
approx() was updated in 9f3122fe to work better with numpy arrays,
however at the same time the requirements were tightened from
requiring an Iterable to requiring a Sequence - the former being
tested only on interface, while the latter requires subclassing or
registration with the abc.

Since the ApproxSequence only used __iter__ and __len__ this commit
reduces the requirement to only what's used, and allows unregistered
Sequence-like containers to be used.

Since numpy arrays qualify for the new criteria, reorder the checks so
that generic sequences are checked for after numpy arrays.
2018-11-18 20:01:11 +00:00
Daniel Hahler
c56cc93cbd tox.ini: remove additionally missed mock deps
Ref: https://github.com/pytest-dev/pytest/pull/4415#discussion_r234452144
2018-11-18 19:37:04 +01:00
Daniel Hahler
cdbe2299ec Merge pull request #4409 from blueyed/str
Add Testdir.__str__ to return str(self.tmpdir)
2018-11-18 12:52:31 +01:00
Daniel Hahler
62967b3110 Merge pull request #4367 from blueyed/determine_setup
Optimize/revisit determine_setup
2018-11-18 12:52:07 +01:00
Ronny Pfannschmidt
5c24430555 Merge pull request #4415 from blueyed/extras-testing
setup.py: add "testing" extra requirement
2018-11-18 12:16:06 +01:00
Daniel Hahler
e46f995cc7 setup.py: add "testing" extra requirement
Use this in tox to stream-line base testing requirements.

Closes https://github.com/pytest-dev/pytest/issues/4410.
2018-11-18 08:55:17 +01:00
Anthony Sottile
10cdae8e38 Merge pull request #4414 from asottile/starred_with_side_effect
Fix assertion rewriting involving Starred + side-effects
2018-11-17 16:17:24 -08:00
Daniel Hahler
5fab0ca312 Merge pull request #4403 from RonnyPfannschmidt/fix-4400
Fix #4400 - rearrange the handling of yield test warnings/errors
2018-11-18 00:57:44 +01:00
Daniel Hahler
7f990e2b9a Merge pull request #4408 from blueyed/default-invalid-escape-sequence
tox.ini: do not cause SyntaxWarning with py37  [ci skip]
2018-11-17 20:08:37 +01:00
Anthony Sottile
690a63b921 Fix assertion rewriting involving Starred + side-effects 2018-11-17 10:42:51 -08:00
Daniel Hahler
4c9cde74ab Merge pull request #4411 from blueyed/fix-testpaths-with-pyargs
Fix collection of testpaths with `--pyargs`.
2018-11-17 17:20:29 +01:00
Ronny Pfannschmidt
94e5bdd4e0 Merge pull request #4413 from blueyed/tox-posargs
tox: fix/improve posargs with pexpect factor(s)  [ci skip]
2018-11-17 17:18:31 +01:00
Daniel Hahler
cb1d4044e6 tox: fix/improve posargs with pexpect factor(s) [ci skip] 2018-11-17 15:35:40 +01:00
Daniel Hahler
a252e81ced Fix collection of testpaths with --pyargs
Fixes https://github.com/pytest-dev/pytest/issues/4405.
2018-11-17 13:28:10 +01:00
Daniel Hahler
3acfa3abdc Add Testdir.__str__ to return str(self.tmpdir)
I just expected this with `monkeypatch.setenv("PYTHONPATH", str(testdir))`,
wondering why it was not picked up correctly.
`
2018-11-17 13:18:54 +01:00
Daniel Hahler
084c36d538 tox.ini: do not cause SyntaxWarning with py37 [ci skip]
Do not cause a SyntaxError for something like:

> DeprecationWarning: invalid escape sequence \w

This was happening via pdb++ when it imported pygments (and that had no
compiled .pyc file).
2018-11-17 11:53:15 +01:00
Ronny Pfannschmidt
950d30e6e0 fix #4400 - rearrange the handling of yield test warnings/errors 2018-11-16 13:49:46 +01:00
Ronny Pfannschmidt
5872e1c35a Merge pull request #4392 from nicoddemus/merge-master-into-features
Merge master into features
2018-11-15 06:59:42 +01:00
Daniel Hahler
0385c27343 cacheprovider: do not write README/.gitignore to existing dir
Fixes https://github.com/pytest-dev/pytest/issues/4393.
2018-11-14 22:09:09 +01:00
Bruno Oliveira
9dec146edf Merge pull request #4388 from nicoddemus/release-4.0.0
Release 4.0.0
2018-11-14 15:11:09 -02:00
Bruno Oliveira
c2d6b3524c Preparing release version 4.0.0 2018-11-13 21:01:51 +00:00
Bruno Oliveira
e025974cbd Merge remote-tracking branch 'upstream/master' into release-4.0.0 2018-11-13 20:58:24 +00:00
Bruno Oliveira
fea09cda6c Merge pull request #4383 from nicoddemus/merge-master-into-features
Merge master into features (about to prepare 4.0)
2018-11-13 18:57:41 -02:00
Daniel Hahler
ba457f5feb Optimize/revisit determine_setup 2018-11-13 20:14:24 +01:00
Daniel Hahler
ed91d5f086 config: set invocation_dir in the constructor already
This allows to make use of it when determining the rootdir etc.
2018-11-13 20:14:24 +01:00
Daniel Hahler
b7863a5f48 Merge pull request #4381 from blueyed/callinfo-repr
Fix CallInfo.__repr__ for unfinished call
2018-11-13 18:13:58 +01:00
Aly Sivji
b83e97802e improve failure output 2018-11-13 09:37:02 -06:00
Daniel Hahler
a72eff5a08 Merge pull request #4382 from blueyed/pytester-pop-TOX_ENV_DIR
pytester: pop TOX_ENV_DIR from os.environ
2018-11-13 12:42:51 +01:00
Daniel Hahler
46c8363e12 Merge pull request #4380 from blueyed/improve-ci
Travis: move faster builds to baseline
2018-11-13 12:40:26 +01:00
Bruno Oliveira
557cb6cffe Merge remote-tracking branch 'upstream/master' into merge-master-into-features 2018-11-13 09:01:37 -02:00
Bruno Oliveira
8198e7cd33 Merge pull request #4349 from nicoddemus/pytest4-warnings-as-errors
Change RemovedInPytest4Warnings to errors by default
2018-11-13 08:31:47 -02:00
Daniel Hahler
a6a96469ca pytester: pop TOX_ENV_DIR from os.environ
Closes: https://github.com/pytest-dev/pytest/pull/4378
Fixes: https://github.com/pytest-dev/pytest/issues/4366
2018-11-13 09:02:52 +01:00
Daniel Hahler
27dab4e05f Fix CallInfo.__repr__ for unfinished call
Fixes https://github.com/pytest-dev/pytest/issues/3554
Ref: https://github.com/pytest-dev/pytest/pull/3560
Ref: https://github.com/pytest-dev/pytest/pull/3562
2018-11-13 08:51:43 +01:00
Daniel Hahler
3e05848ab9 AppVeyor: run py{27,37}-xdist first 2018-11-13 01:33:05 +01:00
Daniel Hahler
5902e5a2ce Travis: move faster builds to baseline
- use py27-pexpect,py27-trial,py27-numpy and py37-xdist in baseline,
  using pexpect there catches errors with pdb tests early, and
  py37-xdist is much faster than py37.
- move py34 and py36 out of baseline.
2018-11-13 01:26:22 +01:00
Bruno Oliveira
243d898b38 Merge pull request #4373 from blueyed/py37-by-default
CI: use py37 instead of py36 by default
2018-11-12 20:56:10 -02:00
Aly Sivji
2bffd6829e Move dataclass tests for 3.7 to separate file 2018-11-12 15:36:16 -06:00
Bruno Oliveira
f8f22d29ee Use a custom cache directory for test_stepwise tests
Otherwise the tests will use tox's env cache which makes them flaky
2018-11-12 16:57:39 -02:00
Bruno Oliveira
dc20dedbc7 Change RemovedInPytest4Warnings to errors by default
To keep existing tests which emit RemovedInPytest4Warnings running, decided
to go with a command line option because:

* Is harder to integrate an ini option with tests which already use an ini file
* It also marks tests which need to be removed/updated in 4.1, when
  RemovedInPytest4Warning and related functionality are removed.

Fix #3737
2018-11-12 16:10:57 -02:00
Aly Sivji
4e99c80425 have tests pass in python37; move to separate file 2018-11-12 11:24:15 -06:00
Bruno Oliveira
3cec1482eb Merge branch 'master' into py37-by-default 2018-11-12 14:03:59 -02:00
Bruno Oliveira
0df5ce4082 Fix basepython for linting testenv in tox.ini 2018-11-12 14:03:04 -02:00
Bruno Oliveira
93a9836962 Merge pull request #4374 from blueyed/doctesting
CI: doctesting uses coverage, fiy py37 on AppVeyor
2018-11-12 13:57:58 -02:00
Aly Sivji
a663f60b05 cr 2/n -- refactor compare eq class 2018-11-12 09:28:47 -06:00
Aly Sivji
e1e81e315e code review 1/n -- change hasattr to getattr 2018-11-12 09:28:47 -06:00
Aly Sivji
025d160dfc Update tests to pass in py27 2018-11-12 09:28:47 -06:00
Aly Sivji
a3e388a73a Improve changelog 2018-11-12 09:28:47 -06:00
Aly Sivji
1847cc7420 adding docs and cleaning up 2018-11-12 09:28:47 -06:00
Aly Sivji
87b019d5f9 fix gitignore 2018-11-12 09:28:47 -06:00
Aly Sivji
1184db8273 cleaning up 2018-11-12 09:28:47 -06:00
Aly Sivji
a0ba881c22 Add change to log; name to AUTHORS 2018-11-12 09:28:47 -06:00
Aly Sivji
d42f1e87c3 Add tests for attrs and dataclasses 2018-11-12 09:28:47 -06:00
Aly Sivji
9769bc05c6 moving plugin inside pytest first pass 2018-11-12 09:20:56 -06:00
Daniel Hahler
935b106213 CI: use py37 instead of py36 by default
Closes https://github.com/pytest-dev/pytest/issues/4370.
2018-11-12 03:16:52 +01:00
Daniel Hahler
74366426b9 Travis: use last TOXENV for PATH 2018-11-11 22:08:45 +01:00
Daniel Hahler
9628242423 CI: doctesting uses coverage, fiy py37 on AppVeyor 2018-11-11 21:49:59 +01:00
Bruno Oliveira
9af613bef2 Merge pull request #4372 from nicoddemus/release-3.10.1
Release version 3.10.1
2018-11-11 15:35:21 -02:00
Bruno Oliveira
7b833ce5f9 Merge pull request #4368 from blueyed/toxenv-coverage
Travis: use coverage from existing tox env  [skip appveyor]
2018-11-11 11:57:20 -02:00
Bruno Oliveira
11a9cbd50b Merge pull request #4365 from blueyed/xenial
Travis: use Xenial by default  [skip appveyor]
2018-11-11 11:55:06 -02:00
Bruno Oliveira
2626bd9afa Preparing release version 3.10.1 2018-11-11 13:43:04 +00:00
Bruno Oliveira
b6f16abfe0 Merge pull request #4369 from blueyed/cleanup
Cleanup/follow-up to #4319
2018-11-11 11:38:06 -02:00
Bruno Oliveira
e5a9f92dfb Merge pull request #4337 from blueyed/fix-sym
Fix collection of symlinked files
2018-11-11 11:36:31 -02:00
Daniel Hahler
a6ff5e6bfc Cleanup/follow-up to #4319 2018-11-11 01:38:34 +01:00
Daniel Hahler
be15ad8d25 Fix collection of direct symlinked files not in python_files
Fixes https://github.com/pytest-dev/pytest/issues/4325.
2018-11-11 01:37:06 +01:00
Daniel Hahler
dc9ceda5d2 Travis: use Xenial by default [skip appveyor] 2018-11-11 01:02:06 +01:00
Daniel Hahler
825085f699 Travis: use coverage from existing tox env [skip appveyor] 2018-11-11 00:59:46 +01:00
Daniel Hahler
b1312147e0 Merge pull request #4358 from blueyed/instance
Node: do not add "::()" to nodeid
2018-11-11 00:42:57 +01:00
Daniel Hahler
7ab3d818f0 Merge pull request #4356 from blueyed/fix-equal_with_bash
tests: fix equal_with_bash to handle appearing .coverage files
2018-11-11 00:42:23 +01:00
Daniel Hahler
f551cb9677 Skip Instances with --collect-only 2018-11-10 23:48:02 +01:00
Daniel Hahler
87254ca593 Add test for --deselect without "::()"
Closes: https://github.com/pytest-dev/pytest/issues/4127.
2018-11-10 23:46:41 +01:00
Daniel Hahler
ac8b9c6e9d Node: do not add "::()" to nodeid
Fixes https://github.com/pytest-dev/pytest/issues/4127.
2018-11-10 23:46:41 +01:00
Daniel Hahler
b51c1c3b8d tests: fix equal_with_bash for .coverage files
Fixes https://github.com/pytest-dev/pytest/issues/4162.
2018-11-10 03:24:02 +01:00
Daniel Hahler
e14ca19988 Merge pull request #4352 from blueyed/_check_initialpaths_for_relpath
Fix nodes._check_initialpaths_for_relpath for dirs
2018-11-10 03:18:36 +01:00
Ronny Pfannschmidt
10d27f412b Merge pull request #4360 from blueyed/merge-master
Merge master into features
2018-11-09 17:26:40 +01:00
Daniel Hahler
bee72a6622 Fix nodes._check_initialpaths_for_relpath for dirs
Ref: https://github.com/pytest-dev/pytest/issues/4321#issuecomment-436951894

Hardens some of the not many tests affected by this:

1. `testing/test_session.py::test_rootdir_option_arg` displayed:

> root/test_rootdir_option_arg2/test_rootdir_option_arg.py

2. `test_cmdline_python_namespace_package` displayed "hello/" prefix for:

> hello/test_hello.py::test_hello
> hello/test_hello.py::test_other
2018-11-09 13:16:59 +01:00
Daniel Hahler
1b260a844f Merge branch 'master' into features 2018-11-09 12:49:55 +01:00
Bruno Oliveira
e00f3a2fb7 Merge pull request #4353 from blueyed/test_fileimport
tests: test_fileimport: improve reporting on failure
2018-11-09 08:32:49 -02:00
Daniel Hahler
b92530de78 Merge pull request #4271 from blueyed/pytest_cache
cache_dir: use $TOX_ENV_DIR/ prefix if set
2018-11-09 09:09:45 +01:00
Daniel Hahler
afaad2f82b Merge pull request #4354 from blueyed/minor
A set of minor changes from my Git stashes
2018-11-09 08:25:17 +01:00
Daniel Hahler
a507f44465 cache_dir: use $TOX_ENV_DIR/ prefix if set
Fixes https://github.com/pytest-dev/pytest/issues/4270
2018-11-09 05:29:28 +01:00
Daniel Hahler
d4fdf793b5 Merge pull request #4350 from blueyed/fix-macos-py37
Travis: fix MacOS py37 build
2018-11-09 02:05:47 +01:00
Daniel Hahler
feccf532d2 doc: improve runpytest_subprocess 2018-11-09 02:03:44 +01:00
Daniel Hahler
859b322773 doc: improve/simplify doc for breakpoint behavior 2018-11-09 02:03:44 +01:00
Daniel Hahler
4a74d455de minor: typos 2018-11-09 02:03:44 +01:00
Daniel Hahler
c1bde8e0a2 minor: check bool before function call 2018-11-09 01:37:51 +01:00
Daniel Hahler
560c055b09 Session._collect: use reversed parts 2018-11-09 01:36:20 +01:00
Daniel Hahler
a0890f98d8 tests: harden test_config_error 2018-11-09 01:31:53 +01:00
Daniel Hahler
401a3cd1bc minor: improve FixtureDef.__repr__
Ref: https://github.com/pytest-dev/pytest/pull/4105#pullrequestreview-163486766
2018-11-09 01:27:18 +01:00
Daniel Hahler
b494d3d1c1 tests: test_fileimport: improve reporting on failure 2018-11-09 01:17:36 +01:00
Daniel Hahler
6c06057242 Merge pull request #4336 from blueyed/cwd2
Fix/improve handling of chdir with no-args and testpaths
2018-11-09 00:38:34 +01:00
Daniel Hahler
bb8a8495ff Revert "Attempt to fix macosx build setup"
This reverts commit 28dbffdaf2.

Appears to be not necessary anymore:
https://travis-ci.org/pytest-dev/pytest/jobs/452598885#L906

[skip appveyor]
2018-11-09 00:33:52 +01:00
Bruno Oliveira
423e19909e Merge pull request #4307 from fzarifian/fzarifian-pr4304
#4304 the stepwise plugin must be blocked on cacheprovider plugin block request
2018-11-08 20:42:04 -02:00
Daniel Hahler
f06fe43649 Merge pull request #4330 from blueyed/fix-report-last-write
Fix TypeError in report_collect with _collect_report_last_write
2018-11-08 21:06:17 +01:00
Daniel Hahler
3137c89cf1 Fix/improve handling of chdir with no-args and testpaths
Fixes https://github.com/pytest-dev/pytest/issues/4332.
2018-11-08 17:50:45 +01:00
Daniel Hahler
5dd509c963 Merge pull request #4338 from blueyed/merge-master
Merge master into features
2018-11-08 17:45:05 +01:00
Fabien ZARIFIAN
f48a26f59c Update AUTHORS 2018-11-08 08:12:08 +01:00
Daniel Hahler
9d838fa861 Merge branch 'master' into features
Conflicts:
	src/_pytest/main.py
2018-11-08 02:48:59 +01:00
Daniel Hahler
91404db284 Fix TypeError in report_collect with _collect_report_last_write
`_collect_report_last_write` might be None, when `pytest_collection` was
not called before.  Not sure if this indicates another problem, but it
can be reproduced with `testing/test_collection.py::TestCollector::()::test_getcustomfile_roundtrip`.

Fixes https://github.com/pytest-dev/pytest/issues/4329
2018-11-07 23:42:02 +01:00
Daniel Hahler
4c00552192 Merge pull request #4317 from blueyed/cwd
Handle os.chdir() during collection
2018-11-07 22:49:47 +01:00
Ronny Pfannschmidt
64762d2cfc Merge pull request #4319 from blueyed/harden-test_collect_init_tests
Fix handling of duplicate args with regard to Python packages
2018-11-07 21:48:54 +01:00
Bruno Oliveira
17b8e2d45b Fix linting 2018-11-07 18:32:23 -02:00
Bruno Oliveira
9a884f1ccb Improve changelog a bit 2018-11-07 18:30:13 -02:00
Daniel Hahler
827573c049 cleanup, TODO: use _node_cache 2018-11-07 20:14:07 +01:00
Daniel Hahler
6fce1f0ac7 pkg_roots per session 2018-11-07 20:06:35 +01:00
Daniel Hahler
bbb9d72c13 remove paths/parts 2018-11-07 19:36:19 +01:00
Daniel Hahler
f8b944dee0 pkg_roots 2018-11-07 19:35:25 +01:00
Daniel Hahler
f840521854 harden test_collect_init_tests 2018-11-07 19:29:55 +01:00
Daniel Hahler
134b103605 XXX: revert _collect_seen_pkgdirs 2018-11-07 11:01:39 +01:00
Daniel Hahler
fa35f650b5 Fix handling of duplicate args with regard to Python packages
Fixes https://github.com/pytest-dev/pytest/issues/4310.
2018-11-07 10:06:09 +01:00
Daniel Hahler
cb57159e01 Handle os.chdir() during collection 2018-11-05 23:18:47 +01:00
Bruno Oliveira
1752c7e710 Merge pull request #4314 from RonnyPfannschmidt/bestrelpath-cache-move-to-session
move Bestrelpath cache move to session
2018-11-05 17:51:49 -03:00
Anthony Sottile
176d27440c Merge pull request #4308 from asottile/compare_versions_with_loose_version
Don't string-compare version numbers
2018-11-05 12:42:26 -08:00
Bruno Oliveira
832b59b316 Merge pull request #4312 from Lothiraldan/patch-1
Add missing `-` in front of the new option `--sw`
2018-11-05 17:17:15 -03:00
Ronny Pfannschmidt
f521f5e012 move the _bestrelpathcache to session 2018-11-05 21:07:21 +01:00
Boris Feld
d42c490bc1 Add missing - in front of the new option --sw 2018-11-05 15:39:35 +01:00
Fabien ZARIFIAN
5f61f0d2cb Update __init__.py
As mentionned by @RonnyPfannschmidt, use set_blocked on module stepwise (and it's brother pytest_stepwise like consider_pluginarg method does)
2018-11-05 10:51:15 +01:00
Ronny Pfannschmidt
e253852e4b Merge pull request #4309 from asottile/less_unicode_hax
Use unicode/bytes literals instead of calls
2018-11-05 07:17:13 +01:00
Anthony Sottile
a4819844a4 Use unicode/bytes literals instead of calls 2018-11-04 17:43:24 -08:00
Anthony Sottile
db996335c8 Merge pull request #4302 from jdufresne/pypi
Update pypi.python.org reference to pypi.org
2018-11-04 17:32:56 -08:00
Anthony Sottile
85a3333824 Don't string-compare version numbers 2018-11-04 17:31:48 -08:00
Anthony Sottile
4bf6a07fe2 Merge pull request #4305 from RonnyPfannschmidt/cleanup-tobytes
replace byte/unicode helpers in test_capture with python level syntax
2018-11-04 17:29:41 -08:00
Fabien ZARIFIAN
db70c75807 Create 4304.bugfix.rst 2018-11-05 00:36:25 +01:00
Fabien ZARIFIAN
1793ac38a9 Update __init__.py 2018-11-05 00:21:12 +01:00
Bruno Oliveira
4aa3c4fa2b Merge pull request #4303 from blueyed/fix-changelog
doc: add lost changelog entry
2018-11-04 20:21:06 -03:00
Fabien ZARIFIAN
a447dc86fb Add test to branch 2018-11-05 00:14:35 +01:00
Ronny Pfannschmidt
7cb271b46f replace byte/unicode helpers in test_capture with python level syntax 2018-11-04 22:01:01 +01:00
Fabien ZARIFIAN
c55ca155e9 Update __init__.py
#4304
2018-11-04 21:55:56 +01:00
Ronny Pfannschmidt
5eb4016110 Merge pull request #4301 from nicoddemus/merge-master-into-features
Merge master into features
2018-11-04 20:23:33 +01:00
Daniel Hahler
34152445cf doc: add lost changelog entry
Closes https://github.com/pytest-dev/pytest/issues/4300.

[ci skip]
2018-11-04 18:26:09 +01:00
Jon Dufresne
5e0441d96e Update pypi.python.org reference to pypi.org 2018-11-04 09:02:54 -08:00
Bruno Oliveira
d1c9c54571 Merge pull request #4297 from nicoddemus/release-3.10.0
Release 3.10.0
2018-11-04 12:25:30 -03:00
Bruno Oliveira
bb2ed2f898 Merge pull request #4298 from blueyed/howto
doc: fix HOWTORELEASE.rst
2018-11-03 20:32:54 -03:00
Bruno Oliveira
3d88d1827b Fixed linting 2018-11-03 19:50:19 -03:00
Daniel Hahler
7b5f3fe83a doc: fix HOWTORELEASE.rst
Remove last step, because it was merged already before (changed in
77cad3c4).

[ci skip]
2018-11-03 21:26:08 +01:00
Daniel Hahler
f2b9bbdd4a Merge pull request #4287 from blueyed/pdb-unconfigure-twice
debugging: make pytest_configure re-entrant
2018-11-03 21:09:13 +01:00
Bruno Oliveira
c2e906ec97 Preparing release version 3.10.0 2018-11-03 13:51:39 +00:00
Bruno Oliveira
1ec6805112 Fix escape in code sample 2018-11-03 13:48:10 +00:00
Bruno Oliveira
6befdf8b46 Merge remote-tracking branch 'upstream/master' into release-3.10.0 2018-11-03 13:42:20 +00:00
Bruno Oliveira
4cb838d978 Merge pull request #4237 from boxed/master
Performance fixes
2018-11-03 10:39:29 -03:00
Daniel Hahler
e61e81a7b5 Make debugging's pytest_configure re-entrant
This is relevant when using runpytest in-process.

Fixes:

E             def test_1(testdir):
E                 testdir.runpytest()
E         >       __import__('pdb').set_trace()
E
E         ../../test_trace_after_runpytest.py:3:
E         …/Vcs/pytest/src/_pytest/debugging.py:81: in set_trace
E             tw = _pytest.config.create_terminal_writer(cls._config)
E
E         config = None, args = (), kwargs = {}, tw = <py._io.terminalwriter.TerminalWriter object at 0x7f1097088160>
E
E             def create_terminal_writer(config, *args, **kwargs):
E                 """Create a TerminalWriter instance configured according to the options
E                 in the config object. Every code which requires a TerminalWriter object
E                 and has access to a config object should use this function.
E                 """
E                 tw = py.io.TerminalWriter(*args, **kwargs)
E         >       if config.option.color == "yes":
E         E       AttributeError: 'NoneType' object has no attribute 'option'
2018-11-02 18:25:01 +01:00
Daniel Hahler
023e1c78df paths: use set and isdisjoint
Time: 5.36s => 4.85s (before rebase: 4.45s => 3.55s)
2018-11-02 17:43:04 +01:00
Daniel Hahler
6ffa347c77 Handle dirs only once
Time: 5.73s/5.88s => 5.36s

(Before rebase: 4.86s => 4.45s)
2018-11-02 17:43:04 +01:00
Anders Hovmöller
2b50911c9d Minor refactor for readability
Time: 5.73s => 5.88s/5.82s
2018-11-02 17:42:53 +01:00
Anders Hovmöller
a41820fbf0 collection: performance: use optimized parts function
Time: 8.53s => 5.73s
2018-11-02 17:42:53 +01:00
Bruno Oliveira
21725e9304 Merge pull request #4285 from kchmck/fix-4046
Fix problems with running tests in package `__init__` files (#4046)
2018-11-02 08:26:07 -03:00
Bruno Oliveira
48f52b1be0 Merge pull request #4279 from williamjamir/improve-warning-msg
Improve the warning message for the implicitly str conversion
2018-11-02 08:22:15 -03:00
Daniel Hahler
a5b3ad2e45 Merge pull request #4284 from blueyed/test-dunder-class
python: collect: ignore exceptions with isinstance
2018-11-01 22:15:29 +01:00
Daniel Hahler
e30f7094f3 python: collect: ignore exceptions with isinstance
Fixes https://github.com/pytest-dev/pytest/issues/4266.
2018-11-01 22:14:13 +01:00
Mick Koch
5197354375 Add changelog entry 2018-11-01 13:13:33 -04:00
Mick Koch
5ac4eff09b Fix __init__.py as argument also including other package files 2018-11-01 13:10:52 -04:00
Mick Koch
320e41b142 Add failing test for __init__.py also including other package files 2018-11-01 13:10:52 -04:00
Mick Koch
70976b04be Add test for __init__.py collection with package directory as argument 2018-11-01 13:10:17 -04:00
Daniel Hahler
d65f300988 Move handling of duplicate files
This removes the hack added in https://github.com/pytest-dev/pytest/pull/3802.

Adjusts test:

- it appears to not have been changed to 7 intentionally.
- removes XXX comment, likely not relevant anymore since 6dac7743.
2018-11-01 13:06:36 -04:00
Anthony Sottile
948fd7b8b0 fixup pyupgrade crlf incorrect fixes 2018-11-01 08:40:35 -07:00
Bruno Oliveira
f2cebce2eb Merge pull request #4272 from blueyed/cache-non-default
cacheprovider: display cachedir also in non-verbose mode if customized
2018-11-01 12:19:21 -03:00
Daniel Hahler
a192e6b430 Merge pull request #4247 from blueyed/lru
_getconftestmodules: use functools.lru_cache
2018-11-01 15:55:38 +01:00
Daniel Hahler
f8a2452247 changelog [ci skip] 2018-11-01 15:53:31 +01:00
Bruno Oliveira
56e6bb0ff6 Merge pull request #4282 from avallbona/patch-1
Update talks.rst
2018-10-31 22:33:45 -03:00
Bruno Oliveira
017e504a11 Merge pull request #4277 from blueyed/pdb-set_trace-capture-msg
pdb: improve msg about output capturing with set_trace
2018-10-31 21:48:47 -03:00
Andreu Vallbona Plazas
9871d5ec2d Updated the talks.rst
corrected the target name
2018-11-01 01:24:18 +01:00
Bruno Oliveira
642521a9b3 Merge pull request #4281 from asottile/bump_hooks
Upgrade pyupgrade for crlf fixes (again)
2018-10-31 20:58:05 -03:00
Bruno Oliveira
0994829afe Move pytest talk to the start of the section 2018-10-31 19:35:47 -03:00
Daniel Hahler
ce1cc3dddb _getconftestmodules: use functools.lru_cache
Also renames `_path2confmods` to `_dirpath2confmods` for clarity (it is
expected to be a dirpath in `_importconftest`).

Uses an explicit maxsize, since it appears to be only relevant for a
short period [1].

Removes the lru_cache on _getconftest_pathlist, which makes no
difference when caching _getconftestmodules, at least with the
performance test of 100x10 files (#4237).

1: https://github.com/pytest-dev/pytest/pull/4237#discussion_r228528007
2018-10-31 23:17:05 +01:00
Daniel Hahler
65817dd797 changelog [ci skip] 2018-10-31 23:13:25 +01:00
Andreu Vallbona Plazas
c31abb1176 Update talks.rst
Added the slides of a PyconES 2017 talk about pytest and its plugins ecosystem.
2018-10-31 23:06:44 +01:00
Bruno Oliveira
d4ca634ef6 Fix linting 2018-10-31 18:21:55 -03:00
Anthony Sottile
af00367fed Upgrade pyupgrade for crlf fixes (again) 2018-10-31 13:26:49 -07:00
William Jamir Silva
9b94313b44 Update changelog 2018-10-31 17:12:50 -03:00
William Jamir Silva
5404246e64 Improve the warning message for the implicitly str conversion
Signed-off-by: William Jamir Silva <williamjamir@gmail.com>
2018-10-31 16:19:10 -03:00
Daniel Hahler
e0038b82f7 pdb: improve msg about output capturing with set_trace
Do not display "IO-capturing turned off/on" when ``-s`` is used to avoid
confusion.
2018-10-31 17:09:01 +01:00
Bruno Oliveira
0fea71a4f5 Merge pull request #4164 from RonnyPfannschmidt/nowarn-session-attributes
don`t parse compat properties as fixtures
2018-10-31 12:52:52 -03:00
Bruno Oliveira
7571f079c8 Merge pull request #4276 from pfctdayelise/flaky-docs
Add docs page discussing flaky tests
2018-10-31 11:25:27 -03:00
Bruno Oliveira
b5d62cdb55 Update 2701.bugfix.rst 2018-10-31 11:07:24 -03:00
Bruno Oliveira
cc25256982 Fix linting2 2018-10-31 11:05:58 -03:00
Ronny Pfannschmidt
da04ff52e4 ignore _CompatProperty when parsing fixtures
this avoid triggering the warnings when parsing the session node as session plugin
2018-10-31 15:01:41 +01:00
Bruno Oliveira
d5b5be6fbe Fix linting 2018-10-31 10:44:43 -03:00
Brianna Laugher
3b65d190a4 Add docs page discussing flaky tests 2018-10-31 23:45:09 +11:00
Daniel Hahler
ff04a1fb09 Merge pull request #4267 from nicoddemus/tmpdir-4262
Fix access denied error when deleting a stale temporary directory
2018-10-31 00:25:13 +01:00
Daniel Hahler
1f1d4aaf68 cacheprovider: display cachedir also in non-verbose mode if customized 2018-10-30 23:09:54 +01:00
Anthony Sottile
196a739f58 Merge pull request #4269 from asottile/upgrade_hooks
Upgrade pre-commit hooks
2018-10-30 14:06:19 -07:00
Bruno Oliveira
f20eeebde9 Fix access denied error when deleting a stale temporary directory
Fix #4262
2018-10-30 15:35:53 -03:00
Anthony Sottile
b17e6cea21 Upgrade pre-commit hooks 2018-10-30 11:02:44 -07:00
Bruno Oliveira
233c2a23de Merge pull request #4250 from blueyed/ignore-pyc
collection: _recurse: skip __pycache__
2018-10-30 08:25:57 -03:00
Bruno Oliveira
46ec0ec43a Merge pull request #4264 from scop/spelling2
Spelling and grammar fixes
2018-10-30 08:24:01 -03:00
Ville Skyttä
a035c89ea7 Spelling fix 2018-10-30 09:38:55 +02:00
Daniel Hahler
40228fce5a collection: _recurse: skip __pycache__ 2018-10-30 02:34:32 +01:00
Anthony Sottile
f258b75a24 Merge pull request #4261 from asottile/no_anonymous_source_warning
Swallow warnings during anonymous compilation of source
2018-10-29 18:29:53 -07:00
Ville Skyttä
22ab737243 Spelling and grammar fixes 2018-10-29 23:45:45 +02:00
Anthony Sottile
0d1f142b1c Swallow warnings during anonymous compilation of source 2018-10-29 08:38:10 -07:00
Anthony Sottile
8c475a45bb Unrelated cleanups of source.py 2018-10-28 16:43:17 -07:00
Bruno Oliveira
e6e40db9c7 Merge pull request #4258 from pecey/tmp/issue-4255
Fixes #4255 by adding to the doc that module names are not regex-escaped
2018-10-28 09:44:13 -03:00
Ronny Pfannschmidt
cc531a1ca9 Merge pull request #4253 from nicoddemus/merge-master-into-features
Merge master into features
2018-10-28 10:13:08 +01:00
Palash Chatterjee
c3acf049bd Fixes #4255 by adding to the documentation that module names are not regex-escaped 2018-10-28 10:45:34 +05:30
Bruno Oliveira
bab1ef5d38 Merge pull request #4257 from Bernardoow/changed_address_to_pytest-datadir
changed address to pytest-data-dir
2018-10-27 17:16:32 -03:00
Bernardo Gomes
b0c0911ba3 changed address to pytest-data-dir 2018-10-27 14:31:50 -03:00
Bruno Oliveira
3b7fbcd47f Merge remote-tracking branch 'upstream/master' into merge-master-into-features 2018-10-27 14:29:01 -03:00
Bruno Oliveira
9ef23b686c Merge pull request #4252 from nicoddemus/release-3.9.3
Preparing release version 3.9.3
2018-10-27 13:36:42 -03:00
Bruno Oliveira
96784c2052 Preparing release version 3.9.3 2018-10-27 13:07:54 +00:00
Ronny Pfannschmidt
9fe871016d Merge pull request #4147 from davidszotten/stepwise
Stepwise
2018-10-27 15:05:05 +02:00
Bruno Oliveira
e986d06ade Merge pull request #4251 from blueyed/python-collect
python: collect: revisit
2018-10-27 10:02:23 -03:00
Bruno Oliveira
ebba3ebe67 Merge pull request #4240 from RonnyPfannschmidt/perf-example-collect-files
add script to generate a example folder for collecting many files
2018-10-26 19:19:02 -03:00
Ankit Goel
1d09e1d8ce Merge pull request #4248 from jdufresne/binary-type
Remove use of unnecessary compat shim, six.binary_type
2018-10-27 00:03:16 +05:30
Bruno Oliveira
d59786fcc4 Merge pull request #4222 from RonnyPfannschmidt/pathlib-fixes
handle race condition when creation and deletion of a numbered dir overlap
2018-10-26 14:36:43 -03:00
Ankit Goel
af34164858 Fix changelog file extension 2018-10-26 22:03:57 +05:30
Daniel Hahler
dcdf86ef5b python: collect: revisit 2018-10-26 16:06:37 +02:00
Jon Dufresne
167e9b954a Remove use of unnecessary compat shim, six.binary_type
The type `bytes` is available on all supported Python versions. On
Python 2.7, it is an alias of str, same as six.binary_type.

Makes the code slightly more forward compatible.
2018-10-26 06:27:50 -07:00
Daniel Hahler
9cde67c09c Merge pull request #4224 from blueyed/_getconftestmodules
_getconftestmodules: avoid isfile()/dirpath()
2018-10-26 14:44:46 +02:00
Ronny Pfannschmidt
ae2fc27799 handle test folder cleanup being unable to create a cleanup lock 2018-10-26 14:31:54 +02:00
Bruno Oliveira
56989a8350 Merge pull request #4244 from RonnyPfannschmidt/fix-4243
fix #4243 - support positional argument stacklevel on python2
2018-10-26 08:09:33 -03:00
Bruno Oliveira
8d0e1a99e4 Merge pull request #4241 from blueyed/move-duplicates
Move handling of duplicate files
2018-10-26 08:07:48 -03:00
Ronny Pfannschmidt
ce0b0518c7 fix #4243 - support positional argument stacklevel on python2 2018-10-26 09:01:25 +02:00
Ronny Pfannschmidt
bf19917537 Merge pull request #4242 from pytest-dev/merge-master
merge master into features
2018-10-26 07:21:59 +02:00
Anthony Sottile
777e9e1e17 Merge remote-tracking branch 'origin/master' into merge-master 2018-10-25 18:00:39 -07:00
Ronny Pfannschmidt
bfa1993840 add script to generate a example folder for collecting many files 2018-10-25 22:07:20 +02:00
Daniel Hahler
e041823643 Move handling of duplicate files
This removes the hack added in https://github.com/pytest-dev/pytest/pull/3802.

Adjusts test:

- it appears to not have been changed to 7 intentionally.
- removes XXX comment, likely not relevant anymore since 6dac7743.
2018-10-25 20:48:08 +02:00
Daniel Hahler
63691f5656 _getconftestmodules: avoid isfile()/dirpath()
Ref: https://github.com/pytest-dev/pytest/issues/2206#issuecomment-432623646
2018-10-25 20:25:07 +02:00
Daniel Hahler
6dc575f5ee Merge pull request #4239 from blueyed/lru_cache
Move lru_cache wrapper to compat
2018-10-25 20:09:01 +02:00
Daniel Hahler
0dc6cb298e Move lru_cache wrapper to compat
Ref: https://github.com/pytest-dev/pytest/pull/4227#discussion_r228060373
2018-10-25 18:20:36 +02:00
Bruno Oliveira
041044eef0 Merge pull request #4238 from asottile/cl
Add a changelog for #4235 [ci skip]
2018-10-25 13:14:05 -03:00
Anthony Sottile
1af31a09f4 Add a changelog for #4235 [ci skip] 2018-10-25 09:09:25 -07:00
Daniel Hahler
f466105d66 Merge pull request #2619 from blueyed/pdb-resume-capture
pdb: resume capturing after `continue`
2018-10-25 14:28:47 +02:00
Bruno Oliveira
ccdb248397 Merge pull request #4235 from asottile/reorder_python_imports
Apply reorder-python-imports to all files
2018-10-25 08:37:40 -03:00
Daniel Hahler
ede3a4e850 pytest_{enter,leave}_pdb: pass through pdb instance 2018-10-25 13:28:24 +02:00
Daniel Hahler
a4ea66cb1f pdb: resume capturing after continue
After `pdb.set_trace()` capturing is turned off.
This patch resumes it after using the `continue` (or `c` / `cont`)
command.

Store _pytest_capman on the class, for pdbpp's do_debug hack to keep it.

Without this, `debug …` would fail like this:

    /usr/lib/python3.6/cmd.py:217: in onecmd
        return func(arg)
    .venv/lib/python3.6/site-packages/pdb.py:608: in do_debug
        return orig_do_debug(self, arg)
    /usr/lib/python3.6/pdb.py:1099: in do_debug
        sys.call_tracing(p.run, (arg, globals, locals))
    /usr/lib/python3.6/bdb.py:434: in run
        exec(cmd, globals, locals)
    /usr/lib/python3.6/bdb.py:51: in trace_dispatch
        return self.dispatch_line(frame)
    /usr/lib/python3.6/bdb.py:69: in dispatch_line
        self.user_line(frame)
    /usr/lib/python3.6/pdb.py:261: in user_line
        self.interaction(frame, None)
    .venv/lib/python3.6/site-packages/pdb.py:203: in interaction
        self.setup(frame, traceback)
    E   AttributeError: 'PytestPdb' object has no attribute '_pytest_capman'

- add pytest_leave_pdb hook
- fixes test_pdb_interaction_capturing_twice: would fail on master now,
  but works here
2018-10-25 13:28:24 +02:00
Anthony Sottile
2368fbb63c Apply reorder-python-imports to all files 2018-10-25 00:01:29 -07:00
Ronny Pfannschmidt
f6dfca7182 Merge pull request #4229 from nicoddemus/fix-warning-location
Show node that originated a warning in the warnings summary
2018-10-25 08:26:01 +02:00
Ronny Pfannschmidt
65b97c2f41 Merge pull request #4227 from blueyed/_getconftest_pathlist-lru
Use functools.lru_cache with _getconftest_pathlist
2018-10-25 08:12:51 +02:00
Bruno Oliveira
4a69104af3 Merge pull request #4232 from blueyed/fix-doc-caplog
doc: fix caplog: s/methods/properties/
2018-10-24 19:27:30 -03:00
Bruno Oliveira
1786ad16a7 functools.lru_cache does not exist on Python 2, apply for Python 3 only 2018-10-24 18:59:54 -03:00
Daniel Hahler
2cf4c67e45 doc: fix caplog: s/methods/properties/ 2018-10-24 23:57:11 +02:00
Bruno Oliveira
2ad43ee442 Show node that originated a warning in the warnings summary
Fix #4221
2018-10-24 18:49:53 -03:00
Daniel Hahler
15278aacb9 Merge pull request #4231 from blueyed/fix-master
Fix flake8: os imported, but unused
2018-10-24 23:47:46 +02:00
Daniel Hahler
57caa4e25e Fix flake8: os imported, but unused
Likely due to b6fa4e24.
2018-10-24 23:43:41 +02:00
Daniel Hahler
66ce952da6 Merge pull request #4228 from blueyed/merge-master
Merge master into features
2018-10-24 23:04:52 +02:00
Bruno Oliveira
b6fa4e248f Merge pull request #4028 from asottile/revert_breakpoint_code
Revert patching of breakpointhook as it appears to do nothing
2018-10-24 17:50:19 -03:00
Daniel Hahler
eee8201e4f Merge remote-tracking branch 'origin/master' into merge-master 2018-10-24 22:36:34 +02:00
Daniel Hahler
e690e191fd Merge pull request #4225 from blueyed/collect-performance
TerminalWriter: write "collecting" msg only once every 0.5s
2018-10-24 22:35:53 +02:00
Daniel Hahler
d40cd3ec6b Use functools.lru_cache with _getconftest_pathlist
For pytest's own suite the `cache_info()` looks as follows:

    > session.config._getconftest_pathlist.cache_info()
    CacheInfo(hits=231, misses=19, maxsize=None, currsize=19)

While it does not really make a difference for me this might help with
larger test suites / the case mentioned in
https://github.com/pytest-dev/pytest/issues/2206#issuecomment-432623646.
2018-10-24 18:22:30 +02:00
Daniel Hahler
9df1b037d6 Merge pull request #4217 from nicoddemus/fix-macos-py37-travis
Fix MacOS py37 on Travis
2018-10-24 17:51:49 +02:00
Bruno Oliveira
28dbffdaf2 Attempt to fix macosx build setup
This has been failing as of 2018-10-23 while installing gcc with
this message:

	==> Installing numpy dependency: gcc
	==> Downloading https://homebrew.bintray.com/bottles/gcc-8.2.0.high_sierra.bottl
	######################################################################## 100.0%
	==> Pouring gcc-8.2.0.high_sierra.bottle.1.tar.gz
	Error: The `brew link` step did not complete successfully
	The formula built, but is not symlinked into /usr/local
	Could not symlink include/c++
	Target /usr/local/include/c++
	already exists. You may want to remove it:
	  rm '/usr/local/include/c++'
	To force the link and overwrite all conflicting files:
	  brew link --overwrite gcc
	To list all files that would be deleted:
	  brew link --overwrite --dry-run gcc
	Possible conflicting files are:
	/usr/local/include/c++ -> /usr/local/Caskroom/oclint/0.13.1,17.4.0/oclint-0.13.1/include/c++
2018-10-24 12:46:45 -03:00
Daniel Hahler
f8f4c16020 TerminalWriter: write "collecting" msg only once every 0.1s
Running `pytest -k doesnotmatch` on pytest's own tests takes ~3s with
Kitty terminal for me, but only ~1s with `-q`.
It also is faster with urxvt, but still takes 2.2s there.

This patch only calls `report_collect` every 0.1s, which is good enough
for reporting collection progress, and improves the time with both Kitty
and urxvt to ~1.2s for me.
2018-10-24 16:48:35 +02:00
Bruno Oliveira
8bced7415c Merge pull request #4220 from anpr/doc_raise_on_empty_parameterset
Add `empty_parameter_set_mark` ini option documentation to the parametrize doc
2018-10-23 19:10:44 -03:00
Bruno Oliveira
72d98a7c52 Merge pull request #4214 from blueyed/fix-4174
Fix "Plugin already registered" error with symlinks
2018-10-23 17:10:15 -03:00
Andreas Profous
0dd85157ea Add reference to `empty_parameter_set_mark` parametrize doc 2018-10-23 22:03:05 +02:00
Daniel Hahler
2a45851c9e Merge pull request #4218 from blueyed/remove-_shutil_rmtree_remove_writable
minor: remove unused _shutil_rmtree_remove_writable
2018-10-23 18:34:28 +02:00
Daniel Hahler
b51ee48f78 minor: remove unused _shutil_rmtree_remove_writable 2018-10-23 17:36:22 +02:00
Daniel Hahler
fadac0ffc0 Fix "Plugin already registered" error with symlinks
Fixes https://github.com/pytest-dev/pytest/issues/4174.
2018-10-23 10:15:23 +02:00
Anthony Sottile
799b72cf6f Merge pull request #4213 from asottile/flake8_master_fixes
Fixes for flake8 master
2018-10-22 20:08:38 -07:00
Bruno Oliveira
fc0f89ac14 Merge pull request #4215 from nicoddemus/release-3.9.2
Release version 3.9.2
2018-10-22 22:08:16 -03:00
Bruno Oliveira
771e860011 Preparing release version 3.9.2 2018-10-22 21:47:42 +00:00
Anthony Sottile
cb39bd0651 Fixes for flake8 master 2018-10-22 08:50:00 -07:00
Anthony Sottile
c94b2b227e Merge pull request #4208 from nicoddemus/pytestskip-docs-4206
Remove pytest.config example from skipping at module level docs
2018-10-21 10:28:53 -07:00
Ankit Goel
f30911d3af Merge pull request #4209 from nicoddemus/fixture-named-request
Issue a warning when a fixture named 'request' is collected
2018-10-21 05:49:08 +05:30
Ankit Goel
cd72e23f3f Merge pull request #4207 from nicoddemus/recursive-dep-fixtures
Improve error message when a recursive dependency between fixtures is detected
2018-10-20 22:19:21 +05:30
Bruno Oliveira
7bb51b8ceb Issue a warning when a fixture named 'request' is collected
Fix #611
2018-10-20 12:09:44 -03:00
Bruno Oliveira
b9990f77ff Merge pull request #4204 from vbarbaresi/3340_log_hooks
Fix logging usage in hooks pytest_sessionstart/finish
2018-10-20 11:36:06 -03:00
Bruno Oliveira
6b126997e1 Remove pytest.config example from skipping at module level docs 2018-10-20 11:28:39 -03:00
Bruno Oliveira
02ae7d8531 Improve error message when a recursive dependency between fixtures is detected
Fix #2909
2018-10-20 09:44:42 -03:00
Bruno Oliveira
f947cb2613 Merge remote-tracking branch 'upstream/features' into davidszotten/stepwise 2018-10-20 09:18:02 -03:00
Vincent Barbaresi
db106d6085 Fix logging usage in hooks pytest_sessionstart/finish #3340 2018-10-20 09:55:10 +02:00
Bruno Oliveira
b0eed7b56c Merge pull request #4205 from vbarbaresi/fix_typo
fix typo in tmpdir documentation (trivial)
2018-10-19 17:49:32 -03:00
Vincent Barbaresi
51d358a7a9 fix typo in tmpdir documentation 2018-10-19 19:22:04 +02:00
Bruno Oliveira
c54cdd05b8 Merge pull request #4201 from ykantor/patch-1
Update tmpdir.rst - very trivial
2018-10-19 12:13:35 -03:00
Bruno Oliveira
dde147641e Fix linting 2018-10-19 09:33:51 -03:00
Bruno Oliveira
2abd005cc9 Merge pull request #4195 from nicoddemus/issue-3691
Use safe_str() to format warning message about unicode in Python 2
2018-10-19 07:18:29 -03:00
Ronny Pfannschmidt
366b88388b Merge pull request #4200 from asottile/upgrade_hooks
Upgrade pre-commit/pre-commit-hooks to 2.0.0
2018-10-19 08:33:03 +02:00
ykantor
0fc1801d0d Update tmpdir.rst 2018-10-19 05:54:29 +02:00
Anthony Sottile
11ff14be1f Upgrade pre-commit/pre-commit-hooks to 2.0.0 2018-10-18 20:11:35 -07:00
Anthony Sottile
dc0b4efffa Merge pull request #4196 from nicoddemus/better-signature-error-msg-4026
Improve error message when it is not possible to determine a function's signature
2018-10-18 18:56:55 -07:00
Bruno Oliveira
864d7fef30 Add back some {posargs} placeholders for pytest invocations in tox.ini
Those were removed by accident in a previous commits it seems
2018-10-18 21:57:11 -03:00
Bruno Oliveira
18035211f5 Use safe_str() to format warning message about unicode in Python 2
Fix #3691
2018-10-18 21:56:17 -03:00
Anthony Sottile
61080da89d Merge pull request #4192 from asottile/fix_recwarn_stacklevel
Fix filename reported by `warnings.warn` when using `recwarn` under python2.
2018-10-18 16:22:00 -07:00
Bruno Oliveira
ac5704290f Improve error message when it is not possible to determine a function's signature
Fix #4026
2018-10-18 20:06:43 -03:00
Bruno Oliveira
b432f1207c Merge pull request #4190 from nicoddemus/merge-master-into-features
Merge master into features
2018-10-18 19:23:16 -03:00
Anthony Sottile
cdd0e18ca8 Emulate resetting the warnings registry for python 2.x 2018-10-18 10:43:05 -07:00
Bruno Oliveira
43c3f59660 Merge pull request #4188 from svenstaro/make-it-more-colorful
Make --color more colorful
2018-10-18 14:14:53 -03:00
Bruno Oliveira
e4871f7722 Merge pull request #4183 from RonnyPfannschmidt/bump-setuptools
fix #4177 - pin setuptools>=40.0
2018-10-18 07:49:03 -03:00
Bruno Oliveira
517ee588c6 Merge pull request #4186 from nicoddemus/drop-coveralls
No longer upload code coverage to coveralls
2018-10-18 07:48:40 -03:00
Ankit Goel
1b51497936 [WIP] Update warning stacklevel when wrapping warnings.warn 2018-10-18 02:36:41 +00:00
Sven-Hendrik Haase
f694d8d6ad Make --color more colorful 2018-10-18 03:56:58 +02:00
Bruno Oliveira
a83ee197c6 Merge remote-tracking branch 'upstream/master' into RonnyPfannschmidt/bump-setuptools 2018-10-17 19:05:52 -03:00
Bruno Oliveira
12f94b81c0 No longer upload code coverage to coveralls
We have since moved to codecov and uploading to coveralls is breaking
OS-X builds for py37 [1], so we might as well take this opportunity to drop
it.

[1] https://travis-ci.org/pytest-dev/pytest/jobs/442858038
2018-10-17 18:18:08 -03:00
Bruno Oliveira
e6b01b45f1 Merge pull request #4185 from RonnyPfannschmidt/fix-fail
fix test_cleanup_keep for expecting symlinks
2018-10-17 18:15:37 -03:00
David Szotten
e478f66d8b cache is set by the cacheprovider 2018-10-17 21:17:54 +01:00
Ronny Pfannschmidt
56dd7bc551 TestNumberedDir: ignore that symlinks arent created on windows 2018-10-17 21:39:23 +02:00
Bruno Oliveira
8a768b0db0 Merge pull request #4182 from nicoddemus/fix-deprecations-hook-name
Fix hook name in deprecations.rst
2018-10-17 16:18:52 -03:00
Ronny Pfannschmidt
8dca8f3c9f fix test_cleanup_keep for expecting symlinks 2018-10-17 21:16:44 +02:00
Ronny Pfannschmidt
cc335d44a0 fix #4179 - bring back the current testrun symlink 2018-10-17 20:43:27 +02:00
Ronny Pfannschmidt
4f4c91caf5 fix #4177 - pin setuptools>=40.0 2018-10-17 20:08:07 +02:00
Bruno Oliveira
ba5a295544 Fix hook name in deprecations.rst
As mentioned in https://github.com/pytest-dev/pytest/issues/4128#issuecomment-430690498
2018-10-17 14:53:41 -03:00
Bruno Oliveira
93bdbf7572 Merge pull request #4173 from nicoddemus/warning-docs-update
Update warnings docs
2018-10-17 09:24:32 -03:00
Anthony Sottile
ab8907f6f5 s/comparision/comparison/g [ci skip] 2018-10-16 17:23:29 -07:00
Bruno Oliveira
215a2ed3de Update warnings docs
Some points on the document work different in 3.9, plus changed the order
of the sections a bit to make more sense for users reading it for the first time.
2018-10-16 21:00:57 -03:00
Bruno Oliveira
f7285b6ab2 Merge pull request #4172 from nicoddemus/merge-features-into-master
Merge features into master
2018-10-16 18:59:23 -03:00
Bruno Oliveira
ee0a306ee4 Merge remote-tracking branch 'upstream/features' into merge-features-into-master 2018-10-16 17:41:27 -03:00
Bruno Oliveira
7931b5b489 Merge pull request #4171 from RonnyPfannschmidt/release-3.9.1
Release 3.9.1
2018-10-16 17:40:31 -03:00
Ronny Pfannschmidt
c5bbf8ac73 make note about the unpublished 3.9.0 release 2018-10-16 22:21:15 +02:00
Ronny Pfannschmidt
253c5786af Preparing release version 3.9.1 2018-10-16 22:16:58 +02:00
Ronny Pfannschmidt
c4550bc922 Merge branch 'release-3.9.0' of github.com:nicoddemus/pytest into release-3.9.1 2018-10-16 22:07:38 +02:00
Bruno Oliveira
2c00f8aad1 Merge pull request #4170 from RonnyPfannschmidt/fix-metadata-url-quotes
Fix metadata url quotes
2018-10-16 16:58:36 -03:00
Ronny Pfannschmidt
456715a5c1 fix url quotes in setup.cfg metadata 2018-10-16 21:48:39 +02:00
Ankit Goel
f858177495 Merge pull request #4167 from vbarbaresi/3533_junit_escape_skipped
Fix #3533: properly escape raw XML object
2018-10-16 21:10:42 +05:30
Bruno Oliveira
54b8ad4554 Merge pull request #4159 from thisch/subclassedfile
Increase required verbosity level for debug output
2018-10-16 10:41:27 -03:00
Vincent Barbaresi
d72154acda add changelog for #3533 2018-10-16 15:07:23 +02:00
Vincent Barbaresi
f55ded20a9 fix #3533: properly escape raw XML object
Using string formatting with the raw escaped object lead to string evaluation
"<py._xmlgen.raw object>"
Format the unescaped string first, then use the XML escape method as a last step.
2018-10-16 14:46:39 +02:00
Bruno Oliveira
17655b54f2 Merge pull request #4163 from nicoddemus/travis-passenv-4162
Pass TRAVIS env var to test environments [skip appveyor]
2018-10-15 20:50:43 -03:00
Bruno Oliveira
12edc4e7b8 Pass TRAVIS env var to test environments [skip appveyor]
xdist has an workaround inplace for Travis so "-n auto" works.

Fix #4162
2018-10-15 20:06:59 -03:00
David Szotten
c25310d34f fix cacheprovider test 2018-10-15 21:51:15 +01:00
Bruno Oliveira
2868c31495 Preparing release version 3.9.0 2018-10-15 20:23:30 +00:00
Bruno Oliveira
39a13d7064 Fix tmp_path example in docs 2018-10-15 20:19:15 +00:00
Bruno Oliveira
e4e4fd1e52 Merge pull request #4158 from nicoddemus/merge-master-into-features
Merge master into features (prepare for 3.9, pt2)
2018-10-15 17:12:08 -03:00
David Szotten
d67d189d00 grammar 2018-10-15 20:04:39 +01:00
David Szotten
8187c148d9 now pinned to pytest version 2018-10-15 20:04:39 +01:00
David Szotten
e773c8ceda linting 2018-10-15 20:04:39 +01:00
David Szotten
4f652c9045 we have a pr number now 2018-10-15 20:04:39 +01:00
David Szotten
126bb0760e authors 2018-10-15 20:04:39 +01:00
David Szotten
8c059dbc48 draft changelog 2018-10-15 20:04:39 +01:00
David Szotten
fd66f69c19 draft doc 2018-10-15 20:04:39 +01:00
David Szotten
63c01d1541 update for builtin plugin 2018-10-15 20:04:39 +01:00
David Szotten
c56d7ac40e move files into the pytest file structure 2018-10-15 20:04:39 +01:00
David Szotten
d9c428c1de add compat for pytest 3.7 and tox config for (some of) the versions i could still get working 2018-10-15 20:04:39 +01:00
Niclas Olofsson
bd9495486b pytest 2.7 compatibility. 2018-10-15 20:04:39 +01:00
Niclas Olofsson
33f1ff4e8c Use result.stderr in tests since result.errlines has changed behaviour. 2018-10-15 20:04:39 +01:00
Niclas Olofsson
1d23bef3fb Use a single node ID rather than a set for failed tests. 2018-10-15 20:04:38 +01:00
Niclas Olofsson
661055105c Restructured project. 2018-10-15 20:04:38 +01:00
Thomas Hisch
e8c220b9bd Increase required verbosity level for debug output
To show the subclassed file in legacy test suits in the runtest output
you have to set the verbosity level to at least "-vv" now.

Closes #3211
2018-10-15 20:38:32 +02:00
Bruno Oliveira
9646a1cd7a Merge remote-tracking branch 'upstream/master' into merge-master-into-features 2018-10-15 12:55:28 -03:00
Bruno Oliveira
9087ac4010 Merge pull request #4157 from nicoddemus/fix-pr-template-link
Use full link to changelog's README in PR template
2018-10-15 12:50:16 -03:00
Anthony Sottile
093e19a7d9 Merge pull request #4153 from asottile/syntax_warning_filename
Display the filename when encountering `SyntaxWarning`.
2018-10-15 08:40:51 -07:00
Bruno Oliveira
9e867ce864 Use full link to changelog's README in PR template
Fix #4156
2018-10-15 12:19:52 -03:00
Bruno Oliveira
8abf30ad71 Merge pull request #4155 from Tadaboody/Add_a_simple_example_on_how_to_use_pytester_to_the_CONTRIBUTING_guide_4151
Add testdir examples to CONTRIBUTING guide
2018-10-15 08:48:57 -03:00
Bruno Oliveira
ea25eb1ecc Fix linting 2018-10-15 08:15:40 -03:00
Bruno Oliveira
58b6e8616c Merge pull request #4149 from RonnyPfannschmidt/modern-build
modernize packaging for setuptools>30.3
2018-10-15 08:13:47 -03:00
Bruno Oliveira
f129ba617f Improve docs a bit 2018-10-15 08:00:16 -03:00
Tomer Keren
99d957bd3d Check off PR requirements 2018-10-15 11:36:31 +03:00
Tomer Keren
661013c3e9 Add testdir examples to CONTRIBUTING guide
Hopefully Closes: #4151
2018-10-15 11:13:24 +03:00
Ankit Goel
141c51f0cb Merge pull request #4145 from labcodes/4098
Add returncode argument to pytest.exit
2018-10-15 11:04:11 +05:30
Ronny Pfannschmidt
d65c7658d5 changelog 2018-10-15 07:32:38 +02:00
Ronny Pfannschmidt
7855284ef7 move most setuptools parameters over to setup.cfg 2018-10-15 07:30:07 +02:00
Ronny Pfannschmidt
5b0f88712b Merge pull request #4148 from RonnyPfannschmidt/pathlib-cleanup-symlink-is-fine
fix #4135 - handle symlinks in tmp path cleanup
2018-10-15 07:02:13 +02:00
Anthony Sottile
2e42d937dc Display the filename when encountering SyntaxWarning.
```console
$ cd t && rm -rf __pycache__ && pytest t.py -q -c /dev/null; cd ..
.                                                                        [100%]
=============================== warnings summary ===============================
<unknown>:2: DeprecationWarning: invalid escape sequence \.

-- Docs: https://docs.pytest.org/en/latest/warnings.html
1 passed, 1 warnings in 0.01 seconds

```

```console
$ cd t && rm -rf __pycache__ && pytest t.py -q -c /dev/null; cd ..
.                                                                        [100%]
=============================== warnings summary ===============================
/tmp/pytest/t/t.py:2: DeprecationWarning: invalid escape sequence \.
  '\.wat'

-- Docs: https://docs.pytest.org/en/latest/warnings.html
1 passed, 1 warnings in 0.01 seconds
```
2018-10-14 16:11:47 -07:00
Jose Carlos Menezes
27d932e882 Fix order of parameters when raising Exit exception 2018-10-14 18:48:32 -03:00
Jose Carlos Menezes
40091ec2c7 Update pytest.exit docstring 2018-10-14 18:44:53 -03:00
Jose Carlos Menezes
76fb9970c8 Check if returncode is not None before assigning test return code 2018-10-14 18:43:48 -03:00
Jose Carlos Menezes
d32f2c5c14 Change Exit.__init__ params order to keep backward compatibility 2018-10-14 18:42:55 -03:00
Bruno Oliveira
49defa2890 Merge pull request #4144 from nicoddemus/fix-flaky-durations-test
Fix flaky durations test
2018-10-14 18:40:14 -03:00
Bruno Oliveira
fe2dae4885 Merge pull request #4140 from blueyed/ci
Faster CI
2018-10-14 18:39:13 -03:00
Bruno Oliveira
ced62f30ba Attempt to create symlinks even on Windows, skipping when not possible 2018-10-14 18:21:04 -03:00
Jose Carlos Menezes
bbd1cbb0b3 Update changelog to better reading 2018-10-14 18:03:37 -03:00
Jose Carlos Menezes
d4dfd526c1 Update pytest.exit docstring 2018-10-14 18:01:47 -03:00
Ronny Pfannschmidt
d4351ac5a2 modernize packaging for setuptools>30.3 2018-10-14 21:44:32 +02:00
Jose Carlos Menezes
766d2daa06 Update returncode exit test to check exitstatus returrned from test session 2018-10-14 16:41:16 -03:00
Jose Carlos Menezes
836c9f82f1 Set test session exitstatus value from Exit excetion return code 2018-10-14 16:39:43 -03:00
Jose Carlos Menezes
46d6a3fc27 Pass returncode to Error exception when creating instance 2018-10-14 16:36:53 -03:00
Ronny Pfannschmidt
1dfa303b1e fix #4135 - handle symlinks in tmp path cleanup 2018-10-14 21:20:34 +02:00
Bruno Oliveira
6258248865 Merge pull request #4138 from blueyed/cov-pexpect
tox.ini: clean up changedir
2018-10-14 15:41:54 -03:00
Bruno Oliveira
4808145846 test_request_garbage is flaky when running with xdist
Example failure:

https://travis-ci.org/pytest-dev/pytest/jobs/441305926#L545
2018-10-14 15:17:08 -03:00
Jose Carlos Menezes
a0666354dd Update changelog 2018-10-14 12:29:19 -03:00
Jose Carlos Menezes
ce55dcf64c Add test for calling pytest.exit with statuscode
It checks that a SystemError was raised and the SystemError code
is the same as the returncode argument.
2018-10-14 12:29:19 -03:00
Jose Carlos Menezes
d7be039f1b Add returncode argument to pytest.exit
If the argument is not None, it'll raise a SystemExit exception to
cleanly exit pytest.
2018-10-14 12:26:31 -03:00
Bruno Oliveira
7e1fac5f91 Merge pull request #4139 from blueyed/passenv
tox.ini: passenv: COVERAGE_*
2018-10-14 12:24:28 -03:00
Bruno Oliveira
486ded3fca Fix flaky durations test
Unfortunately due to fluctuations in runtime "test_something"
might still appear in the final message.

Example failure:

https://ci.appveyor.com/project/pytestbot/pytest/builds/19494829/job/8lx847u0c78m63wf
2018-10-14 12:22:56 -03:00
Daniel Hahler
0be84cd68b Merge pull request #4141 from blueyed/testpaths-fix
tox.ini: fix testpaths
2018-10-14 17:21:10 +02:00
Daniel Hahler
323c846ce6 tox.ini: fix testpaths
Broken recently in 307fa7a4 (features branch).

[ci skip] (since it apparently is not tested/used there)
2018-10-14 17:05:28 +02:00
Daniel Hahler
3bd9f981a2 tox.ini: clean up changedir 2018-10-14 14:33:28 +02:00
Daniel Hahler
7ded937e19 AppVeyor: use fast_finish
This runs py27, py37 and linting first - simulating the baseline stage
used on Travis.
2018-10-14 14:27:34 +02:00
Daniel Hahler
6d0667f1db CI: run specialized factors in a single job
Given the setup time for jobs, it makes sense to run
*-pexpect,*-trial,*-numpy in a single build job.
2018-10-14 14:27:34 +02:00
Daniel Hahler
7c380b19f3 tox.ini: passenv: COVERAGE_*
This is required to pass through COVERAGE_PROCESS_START etc.
2018-10-14 12:34:17 +02:00
Daniel Hahler
5322f422e3 Merge pull request #4108 from blueyed/realpath
Resolve symlinks for args
2018-10-14 11:30:18 +02:00
Daniel Hahler
c6c326f076 Merge pull request #4137 from blueyed/toxini
tox.ini: pexpect: use posargs; cleanup posargs
2018-10-14 11:29:34 +02:00
Daniel Hahler
d6832a8b56 Merge pull request #4133 from blueyed/pdb-quit
pdb: handle quitting in post_mortem
2018-10-14 11:29:09 +02:00
Daniel Hahler
3bfaa8ab84 Merge pull request #4132 from blueyed/pdb-internal-dupe
Do not print (duplicate) INTERNALERROR with --pdb.
2018-10-14 11:25:35 +02:00
Bruno Oliveira
9fb305b17b Merge pull request #4086 from jeffreyrack/4063-exclude-0-durations
Exclude durations that are 0.00 seconds long.
2018-10-13 22:16:04 -03:00
Bruno Oliveira
e3bf9cede4 Fix linting 2018-10-13 22:13:25 -03:00
Daniel Hahler
4a49715614 tox.ini: pexpect: use posargs; cleanup posargs
- no need for {posargs:testing} really
- remove `-ra`, used with addopts already
2018-10-14 00:08:46 +02:00
Daniel Hahler
86c7dcff68 pdb: handle quitting in post_mortem
`help quit` in pdb says:

> Quit from the debugger. The program being executed is aborted.

But pytest would continue with the next tests, often making it necessary
to kill the pytest process when using `--pdb` and trying to cancel the
tests using `KeyboardInterrupt` / `Ctrl-C`.
2018-10-14 00:05:45 +02:00
Daniel Hahler
7268462b33 Resolve symlinks for args
This fixes running `pytest tests/test_foo.py::test_bar`, where `tests`
is a symlink to `project/app/tests`: previously
`project/app/conftest.py` would be ignored for fixtures then.
2018-10-13 23:59:05 +02:00
Daniel Hahler
448830e656 Do not print INTERNALERROR with --pdb
This gets printed by the terminal reporter already, and currently
results in the same error being displayed twice, e.g. when raising an
`Exception` manually from `pytest.debugging.pytest_exception_interact`.
2018-10-13 23:56:34 +02:00
Bruno Oliveira
3683d92c53 Adjust the 'durations hidden' message 2018-10-13 18:40:32 -03:00
Daniel Hahler
d3d8d53e41 tests: test_pdb: fix print statements 2018-10-13 23:33:52 +02:00
Jeffrey Rackauckas
7a271a91b0 Fix rounding error when displaying durations in non-verbose mode. 2018-10-13 12:55:17 -07:00
Jeffrey Rackauckas
47f5c29002 Update messaging for --durations when not in verbose mode. 2018-10-13 12:51:04 -07:00
Bruno Oliveira
27d2683a02 Merge pull request #4134 from blueyed/minor
Minor: code style / constant
2018-10-13 16:13:02 -03:00
Bruno Oliveira
792f365c14 Merge pull request #4136 from luziferius/patch-1
docs: deprecation.rst: Add missing arguments to example code
2018-10-13 16:12:49 -03:00
Thomas Hess
91b2797498 docs: deprecation.rst: Add missing arguments to code example
In the proposed new style using `@pytest.mark.parametrize`,
the example function signature missed the actual arguments.
Add the missing arguments
2018-10-13 20:33:31 +02:00
Daniel Hahler
c27c8f41a8 Merge pull request #4123 from blueyed/clarify
tests: clarify/document/harden acceptance tests
2018-10-13 18:26:10 +02:00
Daniel Hahler
ee54fb9a6b pytester: use EXIT_INTERRUPTED 2018-10-13 17:06:40 +02:00
Daniel Hahler
10ddc466bf minor: typo and code style 2018-10-13 17:06:40 +02:00
Bruno Oliveira
24c83d725a Merge pull request #4129 from nicoddemus/merge-master-into-features
Merge master into features (prepare for 3.9)
2018-10-13 12:05:54 -03:00
Daniel Hahler
6bf4692c7d acceptance_test: clarify/document/fix tests
Ref: e2e6e31711 (r30863971)
2018-10-13 14:41:17 +02:00
Daniel Hahler
81426c3d19 tests: harden test_cmdline_python_package_symlink 2018-10-13 14:41:12 +02:00
Bruno Oliveira
ed42ada373 Merge pull request #4124 from nicoddemus/traceback-import-error-3332
Improve tracebacks for ImportErrors in conftest
2018-10-13 09:25:10 -03:00
Daniel Hahler
e2667106a2 Merge pull request #4126 from blueyed/testpaths
tox.ini: use testpaths, cleanup other pytest options
2018-10-13 14:10:44 +02:00
Bruno Oliveira
29d5849519 Merge remote-tracking branch 'upstream/master' into merge-master-into-features 2018-10-13 08:50:32 -03:00
Bruno Oliveira
eabf15b626 Merge pull request #4125 from nicoddemus/docs-baseline
Run docs, doctesting and linting in the same job to save some CI time
2018-10-12 21:01:59 -03:00
Bruno Oliveira
2dc619cbf4 Run docs, doctesting and linting in the same environment to save some CI time 2018-10-12 13:35:27 -03:00
Daniel Hahler
307fa7a42a tox.ini: use testpaths, cleanup other pytest options 2018-10-12 17:07:45 +02:00
Bruno Oliveira
ef97121d42 Removed unused ConftestImportFailure.__str__ method 2018-10-12 10:57:13 -03:00
Ankit Goel
d46b6b2bc3 Merge pull request #4121 from labcodes/3713
Update usefixtures documentation
2018-10-12 19:08:40 +05:30
Bruno Oliveira
2cb3534679 Move filter_traceback to _pytest._code 2018-10-12 10:19:50 -03:00
Bruno Oliveira
8e11fe5304 Improve tracebacks for ImportErrors in conftest.py files
Fix #3332
2018-10-12 10:10:55 -03:00
Bruno Oliveira
36dc671843 New ExceptionInfo.getrepr 'chain' parameter to be able to suppress chained exceptions 2018-10-12 10:08:55 -03:00
Jose Carlos Menezes
dbaa9464ba Update usefixtures documentation
Clarifying that it can't be used with fixture functions
2018-10-12 09:45:49 -03:00
Bruno Oliveira
933de16fe4 Merge pull request #3988 from RonnyPfannschmidt/tmpdir-port-pathlib
Tmpdir port pathlib
2018-10-12 08:33:47 -03:00
Bruno Oliveira
e8348a1d12 Merge pull request #4077 from nicoddemus/short-usage-errors
Improve internal error messages
2018-10-12 08:18:07 -03:00
Bruno Oliveira
0f5263cdc3 Merge pull request #4109 from njonesu/master
Fix multiple string literals on a line #4093
2018-10-11 15:50:08 -03:00
Ronny Pfannschmidt
4736b2bdfb address review comments 2018-10-11 20:48:30 +02:00
Anthony Sottile
8ecdd4e9ff Merge pull request #4104 from asottile/deprecated_call_match
Implement pytest.deprecated_call with pytest.warns
2018-10-11 08:20:13 -07:00
Daniel Hahler
b3940666a7 Merge pull request #4103 from blueyed/conftest
conftest: optimize _getconftestmodules
2018-10-11 13:52:48 +02:00
Bruno Oliveira
e20987ce82 Merge pull request #4110 from blueyed/pdb
tests: fixes for pdbpp
2018-10-11 08:43:24 -03:00
Ronny Pfannschmidt
584051aa90 extend docs with basics about tmp_path and tmp_path_facotry 2018-10-11 10:33:59 +02:00
Ronny Pfannschmidt
16e2737da3 implement tmp_path_factory and deprecate pytest.ensuretemp as intended 2018-10-11 09:41:37 +02:00
Ronny Pfannschmidt
36c2a101cb add missing docstring 2018-10-11 07:15:09 +02:00
Ronny Pfannschmidt
ebd597b2fd use the constant for lock timeouts 2018-10-11 07:15:09 +02:00
Ronny Pfannschmidt
94829c391b make tmpdir env cleanup idempotent 2018-10-11 07:15:09 +02:00
Ronny Pfannschmidt
b82d6f7a0b pytester: use per test tmproot 2018-10-11 07:15:09 +02:00
Ronny Pfannschmidt
4a436b5470 resolve in code review commments 2018-10-11 07:15:09 +02:00
Ronny Pfannschmidt
ad6f63edda add changelog 2018-10-11 07:15:09 +02:00
Ronny Pfannschmidt
3036914097 sort out rmtree expectations 2018-10-11 07:15:09 +02:00
Ronny Pfannschmidt
2831cb9ab5 unify paths.py and pathlib.py 2018-10-11 07:15:09 +02:00
Ronny Pfannschmidt
00716177b4 fix missed Path import 2018-10-11 07:15:09 +02:00
Ronny Pfannschmidt
85cc9b8f12 move all the things into _pytest.pathlib 2018-10-11 07:15:08 +02:00
Ronny Pfannschmidt
fed4f73a61 ignore rmtree errors 2018-10-11 07:15:08 +02:00
Ronny Pfannschmidt
d76fa59b35 fix lock timeouts for good this time 2018-10-11 07:15:08 +02:00
Ronny Pfannschmidt
2532dc1dbb fix up lock consideration argument 2018-10-11 07:15:08 +02:00
Ronny Pfannschmidt
642cd86dd1 shape up removal and lock destruction 2018-10-11 07:15:08 +02:00
Ronny Pfannschmidt
b3a5b0ebe1 remove path from exposure 2018-10-11 07:15:08 +02:00
Ronny Pfannschmidt
8b4a29357e fix typo 2018-10-11 07:15:08 +02:00
Ronny Pfannschmidt
ab3637d486 implement cleanup for unlocked folders 2018-10-11 07:15:08 +02:00
Ronny Pfannschmidt
66a690928c bring in purepath and fix an assertion 2018-10-11 07:15:08 +02:00
Ronny Pfannschmidt
8e00280fc1 fix linting 2018-10-11 07:15:08 +02:00
Ronny Pfannschmidt
d053cdfbbb factor out max and iterate on locks and cleanups 2018-10-11 07:15:08 +02:00
Ronny Pfannschmidt
2e39fd89d1 add python27 support by using reduce instead of max 2018-10-11 07:15:08 +02:00
Ronny Pfannschmidt
b48e23d54c port interals of tmpdir to a basic pathlib implementation
this is still lacking locking and cleanup of the folders
2018-10-11 07:15:08 +02:00
Bruno Oliveira
c9a85b0e78 Fix linting 2018-10-10 19:54:39 -03:00
Bruno Oliveira
bf265a424d Minor adjustments found during code review 2018-10-10 19:35:49 -03:00
Bruno Oliveira
5436e42990 Use pytest.fail(..., pytrace=False) when treating user errors
This prevents an enormous and often useless stack trace from showing
to end users.

Fix #3867
Fix #2293
2018-10-10 19:16:53 -03:00
Bruno Oliveira
67f40e18a7 Use attr.s(repr=False) because we customize MarkInfo's repr 2018-10-10 19:13:34 -03:00
Daniel Hahler
52ff1eaf37 _getconftestmodules: optimize 2018-10-10 21:30:33 +02:00
Daniel Hahler
602e74c2a7 Merge pull request #4107 from blueyed/__tracebackhide__
pytester: fix __tracebackhide__ for {re_,fn}match_lines
2018-10-10 20:55:32 +02:00
Daniel Hahler
be511c1a05 tests: add missing expect before sendeof for pdbpp
With pdb++ this additional `expect` is required, otherwise `sendeof()`
will block forever.
2018-10-10 20:50:49 +02:00
Daniel Hahler
f36f9d2698 tests: fix/clarify expect for Pdb
`expect()` expects an regular expression, so "Pdb" is equivalent to
"(Pdb)".

But instead of escaping the parenthesis this patch removes them, to
allow for matching "(Pdb++)", too.
2018-10-10 20:50:49 +02:00
Anthony Sottile
dbfb3ccc42 Add changelog entry 2018-10-10 10:46:09 -07:00
Niklas JQ
d1322570dd Fix issue 4093 2018-10-10 19:45:07 +02:00
Daniel Hahler
4c9015c3b1 Merge pull request #4105 from blueyed/repr
Fix trailing whitespace in FixtureDef.__repr__
2018-10-10 19:28:32 +02:00
Niklas JQ
c14a23d4e4 Fix #4093: multiple string literals on a line 2018-10-10 19:28:31 +02:00
Daniel Hahler
b8fc3e569a pytester: fix __tracebackhide__ for {re_,fn}match_lines 2018-10-10 19:27:43 +02:00
Anthony Sottile
e0f6fce9e9 In python2, display previously warned warnings 2018-10-10 09:37:21 -07:00
Daniel Hahler
d93de6cc67 Fix trailing whitespace in FixtureDef.__repr__ 2018-10-10 18:14:56 +02:00
Anthony Sottile
aeb92accb2 Implement pytest.deprecated_call with pytest.warns 2018-10-10 08:03:23 -07:00
Anthony Sottile
943bbdd8ce Merge pull request #4100 from nicoddemus/merge-master-into-features
Merge master into features
2018-10-10 07:35:09 -07:00
Bruno Oliveira
9a3836a0cf Merge remote-tracking branch 'upstream/master' into merge-master-into-features 2018-10-09 19:34:04 -03:00
Anthony Sottile
4b164d947d Merge pull request #4099 from asottile/re-enable_linting_windows
re-enable linting tox env on windows
2018-10-09 15:16:08 -07:00
Anthony Sottile
11a07211b6 re-enable linting tox env on windows 2018-10-09 13:01:51 -07:00
Anthony Sottile
28a3f0fcb9 Revert "Merge pull request #4094 from pytest-dev/asottile/asottile-patch-1"
This reverts commit c55d641963, reversing
changes made to 8393fdd51d.
2018-10-09 12:50:03 -07:00
Anthony Sottile
b8c30aab2b Merge pull request #4097 from asottile/improve_doc_plugin_load
Fix formatting for plugin loading in conftest
2018-10-09 10:23:04 -07:00
Daniel Hahler
b8958168f5 Merge pull request #4092 from altendky/4073-altendky-subprocessing_timeout-take_2
Correct timing in test_pytester.test_testdir_run_with_timeout()
2018-10-09 18:46:58 +02:00
Anthony Sottile
aaaae0b232 Fix formatting for plugin loading in conftest 2018-10-09 09:30:56 -07:00
Anthony Sottile
c55d641963 Merge pull request #4094 from pytest-dev/asottile/asottile-patch-1
Temporarily disable `linting` env in appveyor
2018-10-08 22:55:34 -07:00
Anthony Sottile
4ec85f934c Temporarily disable linting env in appveyor 2018-10-08 22:54:32 -07:00
Ronny Pfannschmidt
8393fdd51d Merge pull request #4089 from asottile/upgrade_hooks
Upgrade pre-commit hooks
2018-10-09 07:43:28 +02:00
Kyle Altendorf
4071c8a4a8 Correct timing in test_pytester.test_testdir_run_with_timeout() 2018-10-08 21:03:42 -04:00
Anthony Sottile
e8c10d4a98 Merge pull request #4090 from asottile/faster_tests
Improve performance of ~3 of the slowest tests
2018-10-08 17:07:10 -07:00
Anthony Sottile
a86035625c Increase recursion limit (broke xdist tests) 2018-10-08 12:57:45 -07:00
Anthony Sottile
4f631440be Use RuntimeError for py27 + py34 compat 2018-10-08 11:47:06 -07:00
Anthony Sottile
3901569f26 Improve performance of ~3 of the slowest tests 2018-10-08 11:12:55 -07:00
Anthony Sottile
689b856cb7 Merge pull request #4088 from Sup3rGeo/bugfix/announcements-name-victor-maryama
Renamed Victor to full name.
2018-10-08 10:16:20 -07:00
Anthony Sottile
65545d8fb2 Manual fixups of black formatting 2018-10-08 10:12:42 -07:00
Anthony Sottile
1caf6d5907 Upgrade pre-commit hooks 2018-10-08 10:10:46 -07:00
Victor Maryama
55871c68a4 Renamed Victor to full name. 2018-10-08 18:43:50 +02:00
Jeffrey Rackauckas
fc11b81005 Exclude durations that are 0.00 seconds long. 2018-10-07 19:19:48 -07:00
Kyle Altendorf
a6fb4c8268 Merge pull request #4078 from altendky/4073-altendky-subprocessing_timeout
Add timeout for Testdir.runpytest_subprocess() and Testdir.run()
2018-10-07 18:07:06 -04:00
Kyle Altendorf
48dcc67274 Increase timeout in test_testdir_run_with_timeout to decrease false failures 2018-10-06 22:02:33 -04:00
Kyle Altendorf
ccaec8d360 __tracebackhide__ = True 2018-10-06 21:57:03 -04:00
Ronny Pfannschmidt
66609665f2 Merge pull request #4076 from nicoddemus/unittest-param-fixture-msg
Improve error message when TestCase functions use a parametrized fixture
2018-10-06 07:43:57 +02:00
Kyle Altendorf
4b36f9aa64 Tidy timeout checking 2018-10-05 16:46:24 -04:00
Kyle Altendorf
5ecbb0acba Correct new changelog to have newline at end 2018-10-05 10:22:07 -04:00
Kyle Altendorf
20902deb75 Add Kyle Altendorf to AUTHORS 2018-10-05 10:02:59 -04:00
Kyle Altendorf
ed5556bdac Add to docstrings 2018-10-05 10:02:59 -04:00
Kyle Altendorf
ee64f1fb9f Add changelog file for 4073 2018-10-05 10:02:59 -04:00
Kyle Altendorf
8e0e862c84 Stretch out the time assertion for slow AppVeyor 2018-10-05 01:38:01 -04:00
Kyle Altendorf
42422a7f62 Throw away arbitrary args to runpytest_subprocess() 2018-10-05 00:30:25 -04:00
Kyle Altendorf
f3a173b736 Revert "Use signal.alarm() for py2 timeout"
This reverts commit 900cef6397.
2018-10-05 00:05:46 -04:00
Kyle Altendorf
5c38a5160d Slight diff tidy 2018-10-04 23:33:38 -04:00
Kyle Altendorf
dcf9eb0104 Raise an exception on unexpected kwargs 2018-10-04 23:27:01 -04:00
Kyle Altendorf
dd225e1b9d Tidy getting of timeout from kwargs 2018-10-04 23:15:30 -04:00
Kyle Altendorf
900cef6397 Use signal.alarm() for py2 timeout 2018-10-04 23:11:26 -04:00
Kyle Altendorf
0d095fc978 Up timeout to 1 second for test 2018-10-04 23:09:07 -04:00
Kyle Altendorf
dcd635ba0c Correct timeout to check every so often 2018-10-04 23:08:57 -04:00
Kyle Altendorf
33f0338eeb kill and wait for subprocess before raising TimeoutExpired 2018-10-04 22:52:51 -04:00
Kyle Altendorf
d5e5433553 Add descriptive message for timeout 2018-10-04 21:43:41 -04:00
Kyle Altendorf
d2906950ce monotonic.monotonic() -> time.time() 2018-10-04 21:26:08 -04:00
Bruno Oliveira
fe7050ba00 Fix lint 2018-10-04 18:45:30 -03:00
Bruno Oliveira
a1208f5631 Merge pull request #4075 from nicoddemus/dynamic-fixturenames
Fix request.fixturenames to return fixtures created dynamically
2018-10-04 09:21:23 -03:00
Kyle Altendorf
870a93c37b Actually construct TimeoutExpired 2018-10-04 01:02:58 -04:00
Kyle Altendorf
96b2ae6654 Initial pass at timeout for subprocessing pytest
pytest-dev/pytest#4073
2018-10-03 23:56:57 -04:00
Anthony Sottile
b098292352 Merge pull request #4069 from asottile/deindent_4066
Fix source reindenting by using `textwrap.dedent` directly.
2018-10-03 16:11:51 -07:00
Bruno Oliveira
212937eb3e Improve error message when TestCase functions use a parametrized fixture
Fix #2535
2018-10-03 19:43:46 -03:00
Bruno Oliveira
70c7273640 Fix request.fixturenames to return fixtures created dynamically
Fix #3057
2018-10-03 18:50:14 -03:00
Anthony Sottile
e5ab62b1b6 Remove (unused) offset= parameter from deindent() 2018-10-03 13:33:10 -07:00
Anthony Sottile
b8b9e8d41c Remove duplicate test (tested above) 2018-10-03 10:01:06 -07:00
Bruno Oliveira
e712adc226 Merge pull request #4072 from pecey/tmp/issue-4064
Fixes #4064 by correcting the documentation for unit-tests
2018-10-03 12:26:35 -03:00
Palash Chatterjee
f9ac60807c Fixes #4064 by correcting the documentation for unit-tests 2018-10-03 18:11:09 +05:30
Bruno Oliveira
3f03625a5d Merge pull request #4070 from jeffreyrack/4058-update-fixture-docs
Update documentation to indicate a fixture can be invoked more than once in it's scope.
2018-10-03 08:39:41 -03:00
Ronny Pfannschmidt
29d3faed66 Merge pull request #4068 from nicoddemus/merge-master-into-features
Merge master into features
2018-10-03 08:30:39 +02:00
Jeffrey Rackauckas
c5dec6056f Fix wording in fixtures doc. 2018-10-02 21:17:53 -07:00
Jeffrey Rackauckas
642847c079 Update documentation on fixture being invoked more than once in a scope. 2018-10-02 20:53:15 -07:00
Anthony Sottile
f102ccc8f0 Fix source reindenting by using textwrap.dedent directly. 2018-10-02 16:13:35 -07:00
Bruno Oliveira
20f93ae8fa Merge pull request #4067 from beneyal/master
Add pytest.freeze_includes() to reference
2018-10-02 20:02:37 -03:00
Bruno Oliveira
1101a20408 Merge remote-tracking branch 'upstream/master' into merge-master-into-features 2018-10-02 18:13:54 -03:00
Anthony Sottile
df435fa8bd Merge pull request #4065 from asottile/release-3.8.2
Preparing release version 3.8.2
2018-10-02 13:53:52 -07:00
Ben Eyal
a5269b26e0 Add anchor for "Freezing pytest" 2018-10-02 17:54:59 +03:00
Anthony Sottile
d3673c7429 Preparing release version 3.8.2 2018-10-02 07:46:02 -07:00
Ben Eyal
5010e02eda Add pytest.freeze_includes to reference 2018-10-02 17:39:08 +03:00
Bruno Oliveira
25fe3706a4 Merge pull request #4056 from nicoddemus/unicode-vars
Ensure Monkeypatch setenv and delenv use bytes keys in Python 2
2018-10-02 07:56:32 -03:00
Bruno Oliveira
1a323fbd3c Show a warning when non-str is given to Monkeypatch.setenv 2018-10-01 20:07:07 -03:00
Bruno Oliveira
9d971d33be Hide internal pytest.warns traceback 2018-10-01 18:45:08 -03:00
Bruno Oliveira
bc009a8582 Fix test to comply with pypy 6.0 2018-10-01 18:37:27 -03:00
Bruno Oliveira
5e7d427df1 Merge pull request #4060 from nicoddemus/4051-changelog
Improve changelog for #4051
2018-10-01 18:12:52 -03:00
Bruno Oliveira
dd59ed3b18 Merge pull request #4059 from labcodes/documenting-scopes
Add possible values for fixture scope to docs
2018-10-01 17:25:42 -03:00
Bruno Oliveira
20d0f0e56b Improve changelog for #4051 2018-10-01 17:12:05 -03:00
Bruno Oliveira
d24a7e6c5a Issue warning if Monkeypatch.setenv/delenv receive non-strings in Python 2
Fixes the bug described in:

	https://github.com/tox-dev/tox/pull/1025#discussion_r221273830

Which is more evident when using `unicode_literals`.
2018-10-01 17:05:30 -03:00
Jose Carlos Menezes
4dc73bda45 Update changelog 2018-10-01 14:41:30 -03:00
Jose Carlos Menezes
732cc2687d Add possible values for fixture scope to docs 2018-10-01 14:31:28 -03:00
Ronny Pfannschmidt
5d2d64c190 Merge pull request #4057 from jeffreyrack/4051-improve-error-messaging
Improve error messaging when invalid syntax is passed to the -m option
2018-10-01 07:16:59 +02:00
Jeffrey Rackauckas
7a6d16c1eb Adding .rst to end of changelog fragment filename. 2018-09-30 18:45:49 -07:00
Jeffrey Rackauckas
c2179c3127 Improve error messaging when invalid syntax is passed to the -m option 2018-09-30 18:34:56 -07:00
Bruno Oliveira
d8d7f73e1c Merge pull request #4045 from nicoddemus/root-conftest-warning-workaround-4039
Do not issue non-top-level conftest warning when --pyargs is used
2018-09-27 09:26:11 -03:00
Ronny Pfannschmidt
3c23b5b010 Merge pull request #4037 from nicoddemus/deprecate-item-warnings-captured-hook
Document that item parameter of pytest_warning_captured hook is deprecated
2018-09-27 13:20:26 +02:00
Bruno Oliveira
783019a8e6 Rename 4040.trivial.rst to 4040.bugfix.rst 2018-09-27 08:08:03 -03:00
Bruno Oliveira
d2fc7ca6e0 Merge pull request #4041 from Zac-HD/user-properties-type
Ensure user_properties is a list
2018-09-27 08:04:30 -03:00
Bruno Oliveira
2d06927a06 Merge pull request #4040 from ods/summary_passes_less_noisy
Exclude empty reports for passed tests
2018-09-27 08:01:58 -03:00
Denis Otkidach
44d29d887e Changelog entry on excluding empty reports for passed tests 2018-09-26 19:02:35 +03:00
Bruno Oliveira
32c5a113e2 Do not issue non-top-level conftest warning when --pyargs is used
Fix #4039
2018-09-26 12:02:08 -03:00
Bruno Oliveira
ba5630e0f8 Simplify test_pytest_plugins_in_non_top_level_conftest_deprecated 2018-09-26 10:49:14 -03:00
Denis Otkidach
808df48ee8 Test for excluding empty reports for passed tests 2018-09-26 16:44:00 +03:00
Zac-HD
a089a9577e Succinct definition of user_properties 2018-09-26 22:40:11 +10:00
Zac-HD
6be2136f20 Ensure user_properties is a list 2018-09-26 22:04:50 +10:00
Denis Otkidach
f9ab81a493 Exclude empty reports for passed tests 2018-09-26 11:55:39 +03:00
Bruno Oliveira
1636522563 Document that item parameter of pytest_warning_captured hook is deprecated
Our policy is to not deprecate features during bugfix releases, but in this
case I believe it makes sense as we are only documenting it as deprecated,
without issuing warnings which might potentially break test suites.

This will get the word out that hook implementers should not use this parameter
at all.

Fix #4036
2018-09-25 17:38:22 -03:00
Bruno Oliveira
b1fbb2ab92 Merge pull request #4032 from hjwp/patch-1
add documentation of register_assert_rewrite
2018-09-25 08:43:29 -03:00
Daniel Hahler
e85edf5212 Merge pull request #4029 from nicoddemus/warnings-example-deprecation-docs
Add an example on how to update config.warn calls
2018-09-25 13:25:21 +02:00
Bruno Oliveira
b03bad5dbb Fix linting 2018-09-25 08:12:55 -03:00
Harry Percival
19ec300b2a fix rst syntax again 2018-09-25 06:58:47 +01:00
Harry Percival
11442f2ad7 fix rst syntax thing 2018-09-25 06:57:33 +01:00
Harry Percival
97748b6605 mention conftest.py as a good place to do it. 2018-09-25 06:55:28 +01:00
Harry Percival
2b762337bd add documentation of register_assert_rewrite
wip
2018-09-25 06:49:50 +01:00
Bruno Oliveira
9899b8f1fb Add an example on how to update config.warn calls
As commented in https://github.com/pytest-dev/pytest-cov/pull/230#pullrequestreview-157958838
2018-09-23 22:42:09 -03:00
Anthony Sottile
956b3aca97 Revert patching of breakpointhook as it appears to do nothing 2018-09-23 18:39:50 -07:00
Anthony Sottile
4474beeb82 Typo fix [ci skip] 2018-09-23 18:07:28 -07:00
Ronny Pfannschmidt
5d8467bedc Merge pull request #4023 from nicoddemus/deprecated-3.9
Add 3.9 deprecated features to deprecations.rst
2018-09-23 18:21:32 +02:00
Ronny Pfannschmidt
eca3e781b6 Merge pull request #4022 from iwanb/fix_reload
Fix #3539: reload module with assertion rewrite import hook
2018-09-23 18:17:56 +02:00
Bruno Oliveira
0d04aa7c59 Add 3.9 deprecated features to deprecations.rst 2018-09-23 09:26:12 -03:00
iwanb
c61ff31ffa Fix #3539: reload module with assertion rewrite import hook 2018-09-23 13:05:55 +02:00
Ronny Pfannschmidt
e03a19f88d Merge pull request #4021 from nicoddemus/merge-master-into-features
Merge master into features
2018-09-23 11:57:05 +02:00
Bruno Oliveira
fcc5b6d604 Add "deprecation" to possible changelog entries in pre-commit 2018-09-22 18:43:22 -03:00
Bruno Oliveira
42afce27b3 Merge pull request #4019 from nicoddemus/deprecation-warnings-4013
Show deprecation warnings even if filters are customized
2018-09-22 18:17:07 -03:00
Bruno Oliveira
56d0b5a7e2 Merge remote-tracking branch 'upstream/master' into merge-master-into-features 2018-09-22 18:14:36 -03:00
Ankit Goel
ec57cbf82d Merge pull request #4020 from crazymerlyn/release-3.8.1
Preparing release version 3.8.1
2018-09-23 00:56:27 +05:30
CrazyMerlyn
3f6a46c2a4 Preparing release version 3.8.1 2018-09-22 16:34:06 +00:00
Bruno Oliveira
c30184709d Show deprecation warnings even if filters are customized
Fix #4013
2018-09-22 10:25:57 -03:00
Bruno Oliveira
4ba3cb25b0 Merge pull request #4016 from williamjamir/patch-1
Include Python 3.7 on getting started doc
2018-09-21 20:02:25 -03:00
William Jamir Silva
650c458df9 Include Python 3.7 on getting started doc
Close #3932
2018-09-21 19:18:51 -03:00
Ankit Goel
58aa4f91f5 Merge pull request #4012 from maxalbert/fix-docstring-typo
Fix typo in docstring
2018-09-21 22:07:57 +05:30
Maximilian Albert
9b382ed16c Fix typo in docstring 2018-09-21 17:11:15 +01:00
Ronny Pfannschmidt
f02dbaf97f Merge pull request #4010 from nicoddemus/package-len-error-3749
Fix 'Package has no len()' error during collection
2018-09-21 07:40:20 +02:00
Bruno Oliveira
41f6ea13ce Fix 'Package has no len()' error during collection
Fix #3749
2018-09-20 17:53:21 -03:00
Ronny Pfannschmidt
f6eb39df33 Merge pull request #4001 from asottile/fix_bytes_repr_text_mix_python_2
Fix UnicodeDecodeError in assertion with mixed non-ascii bytes repr + text
2018-09-20 22:16:37 +02:00
Bruno Oliveira
7a5e11bbcf Merge pull request #3997 from nicoddemus/deprecation-docs
Introduce deprecations page
2018-09-20 08:22:51 -03:00
Anthony Sottile
7122fa5613 Fix UnicodeDecodeError in assertion with mixed non-ascii bytes repr + text 2018-09-19 20:24:00 -07:00
Bruno Oliveira
7aff81739e Merge pull request #3998 from blueyed/logging-del
logging: del item.catch_log_handler only in teardown
2018-09-19 20:07:19 -03:00
Bruno Oliveira
27772f67c0 Merge pull request #3987 from nicoddemus/fix-find-scope-3941
Fix scope determination with indirect parameters
2018-09-19 20:06:45 -03:00
Bruno Oliveira
10b3b2dc68 Merge pull request #3990 from blueyed/coverage-source
coverage: use modules
2018-09-19 19:55:11 -03:00
Bruno Oliveira
c2841542af Introduce deprecations page
fix #3996
2018-09-19 19:51:29 -03:00
wim glenn
1f28096587 Merge pull request #4003 from pytest-dev/wimglenn-patch-1
seems this subdir is now .pytest_cache not .cache
2018-09-19 14:49:38 -05:00
wim glenn
e86b01e831 Update customize.rst 2018-09-19 14:06:36 -05:00
Thomas Hisch
83802d1494 Merge pull request #3986 from thisch/fb3964
Add support for logging in collection-phase
2018-09-19 20:47:19 +02:00
Bruno Oliveira
d1fa8ae08e Improve CHANGELOG entry 2018-09-19 12:52:10 -03:00
Ronny Pfannschmidt
29dac03314 Merge pull request #3980 from nicoddemus/rewrite-cwd-changed
Fix assertion rewriter crash if cwd changes mid-testing
2018-09-19 17:45:26 +02:00
Daniel Hahler
e7eb7e799b logging: del item.catch_log_handler only in teardown
Without this caplog.record_tuples etc is not available anymore when using
`--pdb`.
2018-09-19 17:17:47 +02:00
Thomas Hisch
18cc74b8d0 Remove useless comment 2018-09-19 15:18:37 +02:00
Bruno Oliveira
7f48f552c1 Fix linting 2018-09-19 10:18:05 -03:00
Bruno Oliveira
1e2e65f0fa Add references to the relevant Python issues 2018-09-19 08:20:23 -03:00
Daniel Hahler
28c9cc7321 coverage: use modules for source
This should increase coverage for subprocesses, where previously
`source` paths were used only from the config file, but not the initial
`--source` argument.
2018-09-19 07:46:19 +02:00
Bruno Oliveira
ccb90b5c46 [WIP] Introduce deprecations page
fix #3996
2018-09-18 20:56:40 -03:00
Thomas Hisch
048342817b Add testcase for logging to file 2018-09-18 21:47:42 +02:00
Thomas Hisch
d1a3aa7b2b Update 3964.rst 2018-09-18 21:31:20 +02:00
Thomas Hisch
e967d4587a Add support for logging in collection-phase
The logging plugin does not output log messages generated during the
collection-phase when live-logging is enabled. This fixes this.

Fixes #3964
2018-09-18 20:18:24 +02:00
Bruno Oliveira
a79dc12f1e Merge pull request #3970 from sambarluc/raise_on_empty_parameterset
Raise exception if parametrize collects an empty parameter set
2018-09-18 08:11:34 -03:00
Bruno Oliveira
37d2469266 Use a PurePath instance to do matching against patterns in assertion rewrite
This way we don't need to have real file system path, which prevents the
original #3973 bug.
2018-09-17 20:29:09 -03:00
Bruno Oliveira
1df6d28080 Fix assertion rewriter crash if cwd changes mid-testing
Unfortunately we need to get a `py.path.local` object to perform the fnmatch
operation, it is different from the standard `fnmatch` module because it
implements its own custom logic. So we need to use `py.path` to perform
the fnmatch for backward compatibility reasons.

Ideally we should be able to use a "pure path" in `pathlib` terms (a path
not bound to the file system), but we don't have those in pylib.

Fix #3973
2018-09-17 20:04:44 -03:00
Daniel Hahler
03eaad376b tox: coverage factor: combine and report 2018-09-17 14:44:47 +02:00
Daniel Hahler
739f9a4a4b Travis: use codecov-bash
Faster to install and will retry uploads on connection errors.
2018-09-17 14:44:47 +02:00
Daniel Hahler
93224f8cf9 tox: remove obsolete whitelist_externals 2018-09-17 14:44:47 +02:00
Ronny Pfannschmidt
bb57186dd4 Merge pull request #3983 from nicoddemus/update-backward-policy
Review backward compatibility policy
2018-09-16 20:43:55 +02:00
Bruno Oliveira
2803eb9fbb Merge pull request #3984 from nicoddemus/fix-docs-formatting
Fix rendering of the ini example for python_files
2018-09-15 12:05:59 -03:00
Andrea Cimatoribus
913c07e414 Add changelog file and new author 2018-09-15 09:18:03 +02:00
Andrea Cimatoribus
4a9f468aac Update documentation 2018-09-15 09:18:03 +02:00
Andrea Cimatoribus
05155e4db0 Fail at parametrize option for empty parameter set
Optionally raise an exception when parametrize collects no arguments.
Provide the name of the test causing the failure in the exception
message.

See: #3849
2018-09-15 09:18:03 +02:00
Ronny Pfannschmidt
f53eff93db Merge pull request #3982 from nicoddemus/ignore-pytest-cache
Ignore pytest cache
2018-09-15 07:21:45 +02:00
Ronny Pfannschmidt
bceaede198 Merge pull request #3978 from nicoddemus/warn-yield-and-compat-properties
Actually deprecate long standing features
2018-09-15 07:19:59 +02:00
Bruno Oliveira
86a14d007d Fix scope determination with indirect parameters
Fix #3941
2018-09-14 21:33:59 -03:00
Bruno Oliveira
a4dd6ee3ce Fix linting 2018-09-14 17:31:01 -03:00
Bruno Oliveira
130cf7e0db Fix rendering of the ini example for python_files
Also added an example using one pattern per line
2018-09-14 17:27:25 -03:00
Bruno Oliveira
cbb41f1ae2 Ignore Sphinx's .doctrees folder 2018-09-14 16:00:35 -03:00
Bruno Oliveira
fa78da3c03 Update backward compatibility policy with new practices 2018-09-14 15:58:22 -03:00
Bruno Oliveira
ae8f3695b5 Move UnformattedWarning to _pytest.warning_types 2018-09-14 15:31:20 -03:00
Bruno Oliveira
87ddb2dbd5 Change flaky test_request_garbage to provide more debug information
This test fails *very* rarely when running in xdist.
2018-09-14 15:25:45 -03:00
Bruno Oliveira
9aa6b0903b .pytest_cache is now automatically ignored by Git 2018-09-14 15:16:40 -03:00
Bruno Oliveira
da6830f19b Introduce UnformattedWarning to keep warning types and messages in _pytest.deprecated 2018-09-14 14:49:05 -03:00
Bruno Oliveira
32ee0b9c88 Move warning messages to _pytest.deprecated 2018-09-13 15:56:50 -03:00
Bruno Oliveira
49800ea134 Merge pull request #3977 from RonnyPfannschmidt/remove-im-func
Remove im_func
2018-09-13 15:46:33 -03:00
Bruno Oliveira
feb8240410 Use self.Function again during collection 2018-09-13 15:44:02 -03:00
Bruno Oliveira
b7dd9154c3 Deprecate custom node types during collection by using special names 2018-09-13 14:55:28 -03:00
Bruno Oliveira
482bd5efd2 Show deprecation warning for cached_setup 2018-09-13 14:25:46 -03:00
Bruno Oliveira
bf074b37a3 Show deprecation warnings for compat properties
Fix #3616
2018-09-13 14:10:30 -03:00
Bruno Oliveira
495a55725b Separate deprecations and removals in the CHANGELOG 2018-09-13 14:02:01 -03:00
Bruno Oliveira
53c9124fc9 Merge pull request #3947 from nicoddemus/warnings-filter-precedence
-W now takes precedence over filters in ini files
2018-09-13 13:23:00 -03:00
Ronny Pfannschmidt
8fe55b1d18 add changelog for fix #3975 2018-09-13 15:40:45 +02:00
Ronny Pfannschmidt
a0ce9a4441 remove the legacy code about im_func and generalize using fix and compat.getimfunc 2018-09-13 15:38:36 +02:00
Daniel Hahler
2cf2dc3d95 Merge pull request #3967 from blueyed/optional-mock
tests: use unittest.mock with py34+
2018-09-13 07:36:42 +02:00
Daniel Hahler
7537e94ddf tests: use unittest.mock with py34+
Fixes https://github.com/pytest-dev/pytest/issues/3965.

Has to work around https://github.com/tox-dev/tox/issues/706.

No coverage for pluggymaster builds is OK though anyway.
2018-09-12 23:21:47 +02:00
Bruno Oliveira
ab40696007 -W now takes precedence over filters in ini files
Fix #3946
2018-09-11 19:00:42 +02:00
Anthony Sottile
2c90b3db9e Merge pull request #3957 from asottile/changelog_files
Improve pre-commit detection for changelog filenames
2018-09-08 10:58:50 -07:00
Anthony Sottile
826adafe2e Improve pre-commit detection for changelog filenames 2018-09-07 09:36:09 -07:00
Anthony Sottile
3dd2933dbd Merge pull request #3948 from nicoddemus/fix-changelog
Amend CHANGELOG with missing #3251
2018-09-07 09:15:09 -07:00
Ronny Pfannschmidt
d12f46caef Merge pull request #3949 from nicoddemus/merge-master-into-features
Merge master into features
2018-09-07 07:58:36 +02:00
Bruno Oliveira
b55351274e Amend CHANGELOG with missing #3251 2018-09-06 18:56:08 -03:00
Bruno Oliveira
c00d934b21 Merge pull request #3933 from nicoddemus/idval-hypothesis-flaky-3707
Use -n auto now that xdist behaves well in Travis and AppVeyor
2018-09-06 15:15:55 -03:00
Bruno Oliveira
6b526cbe6a Merge pull request #3943 from nicoddemus/no-coverage-on-deploy
Disable coverage during deployment stage
2018-09-06 15:15:32 -03:00
Bruno Oliveira
e0539e6ede Merge pull request #3942 from nicoddemus/merge-features-into-master
Merge features into master
2018-09-06 09:35:28 -03:00
Bruno Oliveira
5eb85efa14 Use -n auto now that xdist behaves well in Travis and AppVeyor
This hopefully fixes the flaky test_idval_hypothesis on AppVeyor

Fix #3707
2018-09-06 09:22:13 -03:00
Bruno Oliveira
9ee8d72fd2 Disable coverage during deployment stage
Otherwise it will fail as there's no coverage data to combine/publish
2018-09-06 09:18:47 -03:00
Bruno Oliveira
8c4ca383ca Merge remote-tracking branch 'upstream/features' into merge-features-into-master 2018-09-06 09:15:56 -03:00
Bruno Oliveira
f2a427da25 Merge pull request #3940 from nicoddemus/release-3.8.0
Release 3.8.0
2018-09-06 09:15:00 -03:00
Bruno Oliveira
e0466d0ad8 Merge pull request #3923 from nicoddemus/codecov
Add support for codecov in AppVeyor
2018-09-06 07:02:56 -03:00
Bruno Oliveira
418a66a09f Replace coveralls' badge by codecov's 2018-09-05 22:37:32 -03:00
Bruno Oliveira
5e2bd17d18 White list external "env" used by Travis for coverage 2018-09-05 22:37:32 -03:00
Bruno Oliveira
ec6fca4aa7 Add codecov support to AppVeyor and remove coveralls 2018-09-05 19:50:06 -03:00
Bruno Oliveira
1f20626618 Preparing release version 3.8.0 2018-09-05 21:06:32 +00:00
Bruno Oliveira
69b34f7658 Merge remote-tracking branch 'upstream/master' into release-3.8.0 2018-09-05 18:02:02 -03:00
Bruno Oliveira
531b76a513 Merge pull request #3931 from nicoddemus/internal-warnings
Use standard warnings for internal pytest warnings
2018-09-05 14:05:52 -03:00
Bruno Oliveira
f63c683faa No longer escape regex in pytest.mark.filterwarnings
Fix #3936
2018-09-05 10:20:25 -03:00
Ronny Pfannschmidt
410d5762c0 Merge pull request #3919 from fabioz/master
Improve import performance of assertion rewrite. Fixes #3918.
2018-09-05 14:33:40 +02:00
Bruno Oliveira
ddb308455a Make sure warn is called in test_parameterset_extractfrom 2018-09-05 09:01:29 -03:00
Bruno Oliveira
f42b5019ec Make code_or_warning parameter private for backward-compatibility 2018-09-04 18:53:58 -03:00
Bruno Oliveira
adc9ed85bc Fix test_idval_hypothesis 2018-09-04 18:49:20 -03:00
Bruno Oliveira
4592def14d Improve test_rewarn_functional 2018-09-04 17:02:56 -03:00
Bruno Oliveira
2e0a7cf78d Revert to having just "runtest" as "when" parameter of the pytest_warning_captured hook 2018-09-04 17:01:23 -03:00
Bruno Oliveira
5a52acaa92 Make config no longer optional in parametrize id functions 2018-09-04 16:55:52 -03:00
Bruno Oliveira
6d497f2c77 Fix stacklevel for warning about Metafunc.addcall 2018-09-04 16:50:24 -03:00
Bruno Oliveira
b7560a8808 Keep backward compatibility for code as kw in Node.warn 2018-09-04 16:48:21 -03:00
Bruno Oliveira
d3ca739c00 Use explicit instances when calling warnings.warn_explicit 2018-09-04 16:29:48 -03:00
Bruno Oliveira
3db76ccf3d Fix Cache.warn function to issue a "config" warning 2018-09-04 15:53:17 -03:00
Bruno Oliveira
438f7a1254 Add "setup", "call" and "teardown" values to "when" parameter of pytest_warning_captured hook 2018-09-04 15:53:17 -03:00
Bruno Oliveira
47bf58d69e Make Node.warn support two forms, new and deprecated
As suggested during review, it now accepts two forms:

Node.warn(warning_instance)  (recommended)

Node.warn(code, message)  (deprecated)
2018-09-04 15:53:17 -03:00
Bruno Oliveira
5ef51262f7 Fix reference to PytestWarning in warningsfilter mark 2018-09-04 15:06:14 -03:00
Bruno Oliveira
a054aa4797 Issue assert rewrite warning if tuple >=1 as suggested in review 2018-09-04 14:45:48 -03:00
Bruno Oliveira
f1cfd10c94 Handle cache warnings in tests 2018-09-04 14:44:02 -03:00
Bruno Oliveira
d3f72ca202 Fix linting for warnings.rst 2018-09-04 14:33:41 -03:00
Bruno Oliveira
022c58bf64 Revert pytest_terminal_summary(tryfirst) in warnings module as this breaks tests 2018-09-04 14:26:34 -03:00
Bruno Oliveira
b42518acd5 Change std_warn to receive a single warning instance, addressed review suggestions 2018-09-04 14:20:42 -03:00
Bruno Oliveira
284a2d110f Move warnings import to top level 2018-09-04 13:46:33 -03:00
Bruno Oliveira
9ae0a3cd85 Do not trigger warning about tuples being always True if the tuple has size != 2 2018-09-04 13:41:11 -03:00
Bruno Oliveira
615c671434 Connect string literals 2018-09-04 13:34:05 -03:00
Bruno Oliveira
29bfa5efa4 Merge pull request #3925 from crazymerlyn/fix-exit-code
Fix exit code for command line errors
2018-09-04 11:53:00 -03:00
Bruno Oliveira
016f8f1536 Improve get_fslocation_from_item's docstring 2018-09-04 11:48:11 -03:00
Bruno Oliveira
e9417be9df Add comment about deprecation warnings being shown by default 2018-09-04 11:35:35 -03:00
Bruno Oliveira
c304998ed7 Remove commented out code 2018-09-04 11:35:35 -03:00
Bruno Oliveira
415a62e373 Fix typo in PytestExperimentalApiWarning 2018-09-04 11:35:35 -03:00
Bruno Oliveira
8ce3aeadbf Move PytestExerimentalApiWarning to warning_types 2018-09-04 11:35:35 -03:00
Bruno Oliveira
b818314045 Improve docs for warnings capture and PEP-0506 remarks 2018-09-04 11:35:34 -03:00
Bruno Oliveira
56d414177a Remove nodeid from messages for warnings generated by standard warnings
Standard warnings already contain the proper location, so we don't need
to also print the node id
2018-09-04 11:35:34 -03:00
Bruno Oliveira
0fffa6ba2f Implement hack to issue warnings during config
Once we can capture warnings during the config stage, we can
then get rid of this function

Related to #2891
2018-09-04 11:35:34 -03:00
Bruno Oliveira
60499d221e Add test to ensure that users can suppress internal warnings 2018-09-04 11:35:34 -03:00
Bruno Oliveira
9965ed84da Show deprecation warnings by default if no other filters are configured
Fix #2908
2018-09-04 11:35:34 -03:00
Bruno Oliveira
7e13593452 Add CHANGELOG entries for #2452
Fix #2452
Fix #2684
2018-09-04 11:35:34 -03:00
Bruno Oliveira
208dd3aad1 Add docs for internal warnings and introduce PytestDeprecationWarning
Fix #2477
2018-09-04 11:35:34 -03:00
Bruno Oliveira
19a01c9849 Make PytestWarning and RemovedInPytest4Warning part of the public API 2018-09-04 11:35:34 -03:00
Bruno Oliveira
78ac7d99f5 Deprecate Config.warn and Node.warn, replaced by standard warnings 2018-09-04 11:35:34 -03:00
Bruno Oliveira
0c8dbdcd92 Fix existing tests now that we are using standard warnings 2018-09-04 11:35:34 -03:00
Bruno Oliveira
8e4501ee29 Use std_warn for warning about applying marks directly to parameters 2018-09-04 11:35:34 -03:00
Bruno Oliveira
0100f61b62 Start the laywork to capture standard warnings 2018-09-04 11:35:15 -03:00
Bruno Oliveira
1a9d913ee1 Capture and display warnings during collection
Fix #3251
2018-09-04 11:35:06 -03:00
Bruno Oliveira
51e32cf7cc Remove Python 2.6 specific warning 2018-09-04 11:35:06 -03:00
Bruno Oliveira
3fcc4cdbd5 Make terminal capture pytest_warning_capture
pytest_logwarning is no longer emitted by the warnings plugin,
only ever emitted from .warn() functions in config and item
2018-09-04 11:35:06 -03:00
Bruno Oliveira
ffd47ceefc Implement new pytest_warning_captured hook 2018-09-04 11:35:00 -03:00
Bruno Oliveira
10f21b423a Remove assert for "reprec" because this is no longer set on the pluginmanager
It seems this has no effect since `pluggy` was developed as a separate
library.
2018-09-04 11:35:00 -03:00
Bruno Oliveira
eec7081b8d Make AssertionRewritingrHook use imp_find_module 2018-09-03 10:18:25 -03:00
CrazyMerlyn
b01704cce1 Fix exit code for command line errors
Fixes #3913
2018-09-03 04:16:35 +00:00
Ronny Pfannschmidt
15ede8aab8 Merge pull request #3924 from nicoddemus/enable-pypy
Reenable pypy now that scandir can be installed without a compiler
2018-09-02 17:34:21 +02:00
Bruno Oliveira
f7dc9b9fef Merge pull request #3922 from nicoddemus/skip-xfail-docs-3219
Mention explicitly when pytest.skip and pytest.xfail can be called
2018-09-02 11:40:34 -03:00
Bruno Oliveira
dc13f0b469 Reenable pypy now that scandir can be installed without a compiler
Ref: benhoyt/scandir#105
Ref: #3111
2018-09-02 11:17:06 -03:00
Bruno Oliveira
a13c6a84df Mention explicitly when pytest.skip and pytest.xfail can be called
Fix #3219
2018-09-02 10:42:05 -03:00
Bruno Oliveira
dfa713163a Merge pull request #3921 from nicoddemus/use-constant
Use EXIT_USAGEERROR instead of magic number
2018-09-01 20:09:39 -03:00
Bruno Oliveira
90c00dfd54 Use EXIT_USAGEERROR instead of magic number 2018-09-01 12:03:28 -03:00
Daniel Hahler
f3b9b21996 Merge pull request #3920 from blueyed/branch
tests/CI: enable branch coverage
2018-09-01 16:52:12 +02:00
Bruno Oliveira
885b8a3b4c Fix linting 2018-09-01 11:13:40 -03:00
Bruno Oliveira
4675912d89 Add tests for early rewrite bailout code and handle patterns with subdirectories 2018-09-01 10:59:21 -03:00
Bruno Oliveira
495b44198f Merge pull request #3917 from dhirensr/docs_for_detailed_info
T3566,T3546: added a blurb in usage.rst for usage of flag -r
2018-09-01 10:09:29 -03:00
Bruno Oliveira
8d8e68cf90 Merge pull request #3911 from wimglenn/i18n_width
improve line width estimate
2018-09-01 08:57:44 -03:00
Bruno Oliveira
f3b0caf299 Improve docs for summary report and move it further up in the doc 2018-09-01 08:54:00 -03:00
Bruno Oliveira
75d29acc06 Fix reference to inter-sphinx objects database 2018-09-01 08:48:47 -03:00
Daniel Hahler
cbbb36fc9b tests/CI: enable branch coverage 2018-08-31 19:26:47 +02:00
Fabio Zadrozny
d53e449296 Improve performance of assertion rewriting. Fixes #3918 2018-08-31 12:27:08 -03:00
Ronny Pfannschmidt
01df368d93 Merge pull request #3914 from nicoddemus/merge-master-into-features
Merge master into features
2018-08-31 15:31:00 +02:00
Bruno Oliveira
2256f2f04d Remove test which is no longer required and improve test_lf_and_ff_prints_no_needless_message
* test_lf_and_ff_obey_verbosity is no longer necessary because
  test_lf_and_ff_prints_no_needless_message already checks if the proper messages
  are displayed when -q is used.

* Improve test_lf_and_ff_prints_no_needless_message so we also check that
  the correct message is displayed when there are failures to run
2018-08-31 08:01:55 -03:00
dhirensr
95881c870e T3566,T3546: added a blurb in usage.rst for usage of flag -r 2018-08-31 11:20:15 +05:30
Ronny Pfannschmidt
019e33ee3f Merge pull request #3915 from nicoddemus/quickstart-book-docs
Add pytest Quick Start Guide to the books section in the docs
2018-08-31 07:40:13 +02:00
Bruno Oliveira
19fa01b91d Tweak changelog 2018-08-30 21:17:14 -03:00
Bruno Oliveira
96aad2983b Move code to get width of current line to a function 2018-08-30 21:16:35 -03:00
wim glenn
c18a5b5179 try to be backwards compat 2018-08-30 19:06:20 -05:00
wim glenn
ed4b94a180 add changelog entry 2018-08-30 18:59:58 -05:00
wim glenn
29c5ac71bc improve line width estimate 2018-08-30 18:59:58 -05:00
Bruno Oliveira
84a9f7a263 Add pytest Quick Start Guide to the books section in the docs 2018-08-30 20:18:51 -03:00
Bruno Oliveira
11e591e442 Merge remote-tracking branch 'upstream/master' into merge-master-into-features 2018-08-30 19:55:23 -03:00
Bruno Oliveira
64f00683f2 Merge pull request #3912 from dhirensr/needless_message
Needless message printed with --failed-first and no failed tests #3853
2018-08-30 19:51:49 -03:00
Bruno Oliveira
84a033fd97 Remove extra newline 2018-08-30 19:48:47 -03:00
Bruno Oliveira
0183d46275 Improve CHANGELOG a bit 2018-08-30 19:44:04 -03:00
Bruno Oliveira
9bd4b0a05e Merge pull request #3910 from hoefling/docfix
doc fix: raises accepts tuples instead of lists
2018-08-30 19:41:44 -03:00
Bruno Oliveira
f0e852b4db Merge pull request #2800 from blueyed/coverage
Travis: report coverage with all builds
2018-08-30 19:41:22 -03:00
dhirensr
ade01b1f5b T3853:Added changelog file 2018-08-30 16:03:18 +05:30
dhirensr
3035b2724d T3853:removed needless message printed with --failed-first,--last-failed and no failed tests 2018-08-30 16:01:42 +05:30
hoefling
8c96eea583 doc fix: raises accepts tuples instead of lists (fixes #3907) 2018-08-30 00:19:59 +02:00
Bruno Oliveira
338953a25d Merge pull request #3908 from nicoddemus/optimize-release
Skip the "test" stage when making a release
2018-08-29 18:53:36 -03:00
Anthony Sottile
f1bd46266b Merge pull request #3909 from asottile/update_release
Update release procedure
2018-08-29 14:37:52 -07:00
Anthony Sottile
77cad3c436 Update release procedure [ci skip] 2018-08-29 14:13:08 -07:00
Bruno Oliveira
3ca70692de Skip the "test" stage when making a release
Given that our guidelines demand that the CI have already passed, it seems
wasteful to run all those jobs again for the exact same commit.

As discussed in https://github.com/pytest-dev/pytest/pull/3906#issuecomment-417094481,
this will skip the "test" stage when building a tag for deployment.
2018-08-29 17:54:58 -03:00
Daniel Hahler
417516c378 squash! Travis: report coverage with all builds
doctesting: remove changedir

With coverage 5 we could use COVERAGE_RCFILE to make it find the
.coveragerc, or we could add `--rcfile` to _PYTEST_TOX_COVERAGE_RUN, but
I've thought that this should not be the job that has to test if
`--pyargs` actually works.
2018-08-29 22:53:20 +02:00
Daniel Hahler
f730291e67 Travis: report coverage with all builds
- Skips pypy for coverage, reports only py37 to coveralls
- tox: allow for TOXENV=py37-coverage
- tracks coverage in subprocesses, using coverage-enable-subprocess, and
  parallel=1
- removes usedevelop with doctesting to match `--source` being used with
  coverage
- keep coveralls for now, used with AppVeyor
2018-08-29 22:30:28 +02:00
Anthony Sottile
d76fb8345c Merge pull request #3906 from asottile/release-3.7.4
Preparing release version 3.7.4
2018-08-29 13:03:34 -07:00
Anthony Sottile
aea962dc21 Preparing release version 3.7.4 2018-08-29 08:57:54 -07:00
Bruno Oliveira
4345efaffc Merge pull request #3902 from stevepiercy/fix-pytest.org-links
Fix pytest.org links
2018-08-29 08:20:01 -03:00
Bruno Oliveira
bf47033169 Fix linting 2018-08-28 21:05:34 -03:00
Steve Piercy
37a65684d6 add changelog entry 2018-08-28 14:51:27 -07:00
Steve Piercy
eab5020e24 Fix hostname 2018-08-28 14:45:04 -07:00
Steve Piercy
8ef21f56d3 Fix 404 2018-08-28 14:42:16 -07:00
Steve Piercy
103d980b2d Use https, save a redirect 2018-08-28 14:41:13 -07:00
Steve Piercy
28c3ef1c77 Use https, save a redirect, fix hostname 2018-08-28 14:40:20 -07:00
Steve Piercy
67c3c28877 Use https, save a redirect 2018-08-28 14:39:32 -07:00
Steve Piercy
e040fd20a3 Use https, save a redirect 2018-08-28 14:38:55 -07:00
Steve Piercy
00e0b43010 Use https, save a redirect 2018-08-28 14:36:47 -07:00
Steve Piercy
f19cfbb825 Fix 404 to a somewhat better historical note 2018-08-28 14:35:08 -07:00
Steve Piercy
bde3d1a0cd Use https; save a redirect 2018-08-28 14:34:39 -07:00
Steve Piercy
2e090896d5 Use https 2018-08-28 14:34:22 -07:00
Steve Piercy
b0a32da0b5 Use https; save a redirect 2018-08-28 14:27:11 -07:00
Bruno Oliveira
10c1c7c41a Merge pull request #3895 from nicoddemus/issue-3506
Avoid possible infinite recursion when writing pyc files in assert rewrite
2018-08-28 18:16:10 -03:00
Daniel Hahler
16f452ef98 Merge pull request #3894 from blueyed/baseline
Travis: add baseline stage
2018-08-28 22:19:08 +02:00
Bruno Oliveira
b77e533693 Merge pull request #3893 from jirikuncar/3892-macos
travis: run tests on macOS
2018-08-28 17:06:17 -03:00
Bruno Oliveira
a605ad4d11 Merge pull request #3880 from jeffreyrack/3829-progress_display_mode
#3829 -- Add the ability to show test progress as number of tests completed instead of a percent.
2018-08-28 16:54:14 -03:00
Jeffrey Rackauckas
4b94760c8e Removed spacing in count display. 2018-08-27 20:23:17 -07:00
Bruno Oliveira
82a7ca9615 Avoid possible infinite recursion when writing pyc files in assert rewrite
What happens is that atomic_write on Python 2.7 on Windows will try
to convert the paths to unicode, but this triggers the import of
the encoding module for the file system codec, which in turn triggers
the rewrite, which in turn again tries to import the module, and so on.

This short-circuits the cases where we try to import another file when
writing a pyc file; I don't expect this to affect anything because
the only modules that could be affected are those imported by
atomic_writes.

Fix #3506
2018-08-27 21:29:45 -03:00
Bruno Oliveira
23295e1e98 Fix docs linting 2018-08-27 20:21:08 -03:00
Bruno Oliveira
32575f92c9 set TOXENV in test-macos template otherwise it will inherit "coveralls" 2018-08-27 20:07:51 -03:00
Bruno Oliveira
a260e58020 Drop 3.6 from OS-X to reduce build time 2018-08-27 20:03:12 -03:00
Bruno Oliveira
b2f7e02a02 Reorganize osx environments to avoid repetition as suggested in review 2018-08-27 20:02:16 -03:00
Bruno Oliveira
29e114b463 Try to fix test in MacOS-X 2018-08-27 19:27:51 -03:00
Bruno Oliveira
2a059b1c1b Merge pull request #3885 from nicoddemus/bad-output-classic
Fix bad console output when using console_output_style=classic
2018-08-27 19:07:02 -03:00
Daniel Hahler
cdc72bf5a3 Travis: add baseline stage
Fixes https://github.com/pytest-dev/pytest/issues/3876.
2018-08-27 23:46:24 +02:00
Jiri Kuncar
f786335dbb travis: run tests on macOS
closes #3892
2018-08-27 17:22:27 +02:00
Jiri Kuncar
ab5af524a4 Fix macOS specific code that uses capturemanager.
https://github.com/pytest-dev/pytest/issues/3888#issuecomment-416206606

closes #3888

Co-authored-by: Bruno Oliveira <nicoddemus@gmail.com>
2018-08-27 16:07:59 +02:00
Bruno Oliveira
9620b167d9 Merge pull request #3887 from asottile/improve_test_code
Improve the coverage of testing/code
2018-08-27 07:20:45 -03:00
Jeffrey Rackauckas
8f4685e024 Move count display style to be part of console_output_style, fixed test progress for count console output style. 2018-08-26 19:21:00 -07:00
Anthony Sottile
10544c4cb8 Merge pull request #3886 from nicoddemus/ff-quiet
Cache now obeys -q when showing summary for --lf and --ff
2018-08-26 18:32:22 -07:00
Anthony Sottile
1e8e17c01e Improve the coverage of testing/code 2018-08-26 16:13:22 -07:00
Bruno Oliveira
80eef29681 Merge pull request #3884 from nicoddemus/merge-master-into-features
Merge master into features
2018-08-26 19:41:30 -03:00
Bruno Oliveira
47bb53f5cb Cache now obeys -q when showing summary for --lf and --ff
Related to #3853
2018-08-26 18:08:19 -03:00
Bruno Oliveira
6991a16edb Fix bad console output when using console_output_style=classic
Fix #3883
2018-08-26 17:12:55 -03:00
Bruno Oliveira
2f2d5861bb Merge remote-tracking branch 'upstream/master' into merge-master-into-features 2018-08-26 16:45:00 -03:00
Bruno Oliveira
a31967431f Merge pull request #3882 from nicoddemus/release-3.7.3
Release 3.7.3
2018-08-26 16:41:40 -03:00
Bruno Oliveira
e74ad4ff9b Fix typo in CHANGELOG 2018-08-26 12:27:02 -03:00
Bruno Oliveira
70bdacf01a Fix collection example docs 2018-08-26 12:58:47 +00:00
Bruno Oliveira
b69f853acb Tweak CHANGELOG for 3.7.3 2018-08-26 09:46:46 -03:00
Bruno Oliveira
c31018d9bc Preparing release version 3.7.3 2018-08-26 12:43:43 +00:00
Bruno Oliveira
7ae23901d3 Merge pull request #3881 from GandalfSaxe/patch-2
Code block: :: missing and 4 spaces instead of 5
2018-08-26 09:22:30 -03:00
Bruno Oliveira
4d19b94347 Merge pull request #3877 from blueyed/codecov-master
tox: coveralls: also report to codecov
2018-08-26 09:19:03 -03:00
Bruno Oliveira
c15b537e3d Merge pull request #3878 from asottile/skip_install_linting
Use skip_install for testing tox env
2018-08-26 09:17:40 -03:00
Bruno Oliveira
2577a6ce8a Merge pull request #3873 from nicoddemus/sys-path-fix
Remove dangerous sys.path manipulations in test_pluginmanager
2018-08-26 08:53:57 -03:00
Bruno Oliveira
dd5f5ca4cb Merge pull request #3872 from nicoddemus/tests-in-init-files
Collect tests from __init__.py files if they match 'python_files'
2018-08-26 08:50:17 -03:00
Gandalf Saxe
508774742e Code block: :: missing and 4 spaces instead of 5
I just noticed the newly committed code block doesn't format as a code block without `::` in the paragraph before. Perhaps doesn't make a difference, but also corrected 5 spaces to 4 which seems standard.
2018-08-26 11:54:08 +02:00
Jeffrey Rackauckas
2a917a582e Removing accidental change to test 2018-08-25 22:21:50 -07:00
Jeffrey Rackauckas
325319dc3b Fixing xdist test to properly configure an ini file. 2018-08-25 22:18:29 -07:00
Jeffrey Rackauckas
dda5e5ea32 Fixing backticks in changelog file. 2018-08-25 21:55:00 -07:00
Jeffrey Rackauckas
5e260c4d34 Fixing changelog file. 2018-08-25 21:50:19 -07:00
Daniel Hahler
d3f5324386 tox: coveralls: also report to codecov
This is meant to get base coverage on master for codecov.
2018-08-26 02:14:22 +02:00
Anthony Sottile
3da88d794f Use skip_install for testing tox env 2018-08-25 16:48:01 -07:00
Bruno Oliveira
71b4995775 Merge pull request #3874 from blueyed/improve-pre-commit
Travis: use TOXENV=linting for linting stage
2018-08-25 20:14:27 -03:00
Bruno Oliveira
b0541e9d31 Correctly restore sys.path in test and remove dead code in test_pytester
The code in test_pytester has been refactored into a class right
above the dead code, and the code has been left there by mistake
apparently.
2018-08-25 18:17:52 -03:00
Daniel Hahler
415fcb912b Travis: use TOXENV=linting for linting stage
This will run it with `--show-diff-on-failure` then, and helps to keep
it in line / in a central place.
2018-08-25 23:14:09 +02:00
Bruno Oliveira
f872fcb5d0 Remove dangerous sys.path manipulations in test_pluginmanager
Noticed these while working in something else
2018-08-25 17:33:29 -03:00
Bruno Oliveira
de6f2c0336 Collect tests from __init__.py files if they match 'python_files'
Fix #3773
2018-08-25 11:18:52 -03:00
Bruno Oliveira
be4b359c74 Merge pull request #3861 from jonozzz/fix-3854
Fix #3854
2018-08-25 10:44:08 -03:00
Bruno Oliveira
72a58bbafe Merge pull request #3871 from schmamps/cmdclass
Correct cmdclass for doc: Good Integration Practices
2018-08-24 22:09:35 -03:00
turturica
c336449729 Make linting happy. Argh. 2018-08-24 18:05:35 -07:00
turturica
1e4ecda884 Fix the package fixture ordering in Windows. 2018-08-24 18:01:38 -07:00
turturica
8cf0e46bbf test_package_ordering: Collect *.py, but keep a mix of case for filenames. The test doesn't make sense for Windows, because of its case-insensitivity. 2018-08-24 16:23:50 -07:00
Bruno Oliveira
f0226e9329 Fix test_package_ordering on Windows 2018-08-24 20:15:33 -03:00
turturica
dce8df45d5 Added changelog items. 2018-08-24 15:51:42 -07:00
Andrew Champion
f6948597e4 add to changelog 2018-08-24 12:29:18 -07:00
turturica
e3df1031ca Add encoding: utf8 for python 2.7 2018-08-24 12:26:18 -07:00
Andrew Champion
14ffadf004 correct cmdclass 2018-08-24 12:07:22 -07:00
turturica
459b040d21 Fix dedent after merge. 2018-08-24 11:54:04 -07:00
turturica
3396225f74 Merge branch 'master' of github.com:pytest-dev/pytest into fix-3854 2018-08-24 11:47:24 -07:00
Bruno Oliveira
c82906105c Merge pull request #3865 from GandalfSaxe/patch-1
Move information on `pip install -e` to the top
2018-08-24 07:28:51 -03:00
Anthony Sottile
4c14740798 Merge pull request #3868 from asottile/bytes_py26_plus
Use `bytes` directly instead of `binary_type`
2018-08-23 23:16:59 -07:00
Jeffrey Rackauckas
5fefc48f33 Fixing pre-commit hooks 2018-08-23 23:00:02 -07:00
turturica
72e6482994 Make linting happy. 2018-08-23 22:58:36 -07:00
Jeffrey Rackauckas
93f783228c Add the progress_display_mode ini option 2018-08-23 22:56:25 -07:00
turturica
5f8b50c094 Address #3796 and add a test for it. 2018-08-23 22:48:44 -07:00
Anthony Sottile
99e31f6fb1 Use bytes directly instead of binary_type
`bytes` is an alias for `str` in python2.6+
2018-08-23 18:55:21 -07:00
Anthony Sottile
f2e35c8c4f Merge pull request #3859 from asottile/pyupgrade_1_4
Some pyupgrade 1.4.x changes
2018-08-23 18:32:53 -07:00
Bruno Oliveira
40b4fe64af Fix linting 2018-08-23 22:11:17 -03:00
Bruno Oliveira
d10d59c013 Merge pull request #3858 from mimi1vx/test_mock
Use unittest.mock if is only aviable
2018-08-23 19:02:39 -03:00
wim glenn
d54aa8ce13 Merge pull request #3848 from wimglenn/pytester_unicode_bugfixes
fixed a bunch of unicode bugs in pytester.py
2018-08-23 13:45:49 -05:00
Anthony Sottile
52fa8c98bb Merge pull request #3864 from asottile/source_to_dedent
Replace Source with dedent where possible
2018-08-23 10:45:11 -07:00
Gandalf Saxe
3f336869e2 Move information on pip install -e to the top
Should fix complaints in #2421.
2018-08-23 18:07:28 +02:00
Anthony Sottile
85482d575e Replace Source with dedent where possible 2018-08-23 09:06:17 -07:00
Bruno Oliveira
6f7365509d Merge pull request #3860 from asottile/purge_more_py
Purge more usage of `py` module
2018-08-23 06:05:32 -03:00
Anthony Sottile
7099ea9bb0 py.builtin._reraise -> six.reraise 2018-08-22 23:00:58 -07:00
Anthony Sottile
dccac69d82 py.builtin.text -> six.text_type 2018-08-22 23:00:06 -07:00
Anthony Sottile
c2cd337886 py.builtin.exec_ => six.exec_ 2018-08-22 23:00:06 -07:00
Anthony Sottile
0fc4a806e5 py.builtins._totext -> string literals or six.text_type 2018-08-22 23:00:04 -07:00
turturica
4d3c1ab4f0 Fixes #3854 2018-08-22 21:42:59 -07:00
turturica
e4f76f6350 Merge branch 'master' of github.com:pytest-dev/pytest into fix-3854 2018-08-22 20:36:52 -07:00
Anthony Sottile
0d65783dce Fix unicode errors when changing to .format(...) 2018-08-22 19:00:43 -07:00
Anthony Sottile
8bb8b91357 pyupgrade 1.4: tests 2018-08-22 18:47:21 -07:00
Bruno Oliveira
8804c7333a Fix CHANGELOG formatting 2018-08-22 20:06:13 -03:00
Bruno Oliveira
17eec5b97e Merge pull request #3856 from jennirinker/master
Resolving Issue #3824
2018-08-22 19:03:55 -03:00
Ondřej Súkup
cd07c4d4ff Use unittest.mock if is only aviable
from Python 3.3 is mock part of python standard library in unittest namespace
2018-08-22 23:49:40 +02:00
wim glenn
917b99e438 More unicode whack-a-mole
It seems pytest's very comprehensive CI sniffed out a few other places with similar bugs.  Ideally we should find all the places where args are not stringy and solve it at the source, but who knows how many people are relying on the implicit string conversion.  See [here](https://github.com/pytest-dev/pytest/blob/master/src/_pytest/config/__init__.py#L160-L166) for one such problem area (args with a single py.path.local instance is converted here, but a list or tuple containing some are not).
2018-08-22 13:40:21 -05:00
wim glenn
b08e156b79 strip trailing whitespace 2018-08-22 11:27:36 -05:00
wim glenn
8e2c7b4979 Add a failing testcase for PR #3848 2018-08-22 11:00:51 -05:00
Bruno Oliveira
5a7aa123ea Improve docs formatting 2018-08-22 11:22:30 -03:00
Jennifer Rinker
a12eadd9ef resolving Issue #3824 - expanding docs 2018-08-22 15:37:35 +02:00
Bruno Oliveira
2137e2b15b Merge pull request #3846 from nicoddemus/issue-3843
Fix collection error when tests is specified with --doctest-modules
2018-08-22 08:17:07 -03:00
wim glenn
89446af51e fixed a bunch of unicode bugs in pytester.py 2018-08-22 01:30:23 -05:00
Ronny Pfannschmidt
3b521bedf8 Merge pull request #3841 from sankt-petersbug/fix-3816
Fix '--show-capture=no' capture teardown logs
2018-08-22 07:16:53 +02:00
Ronny Pfannschmidt
5b2c8fa007 Merge pull request #3845 from natanlao/patch-1
Remove warning about #568 from documentation
2018-08-22 07:12:40 +02:00
Bruno Oliveira
eb8d145195 Add link to issue in the CHANGELOG entry 2018-08-21 21:08:21 -03:00
Natan Lao
80bea79512 Add changelog entry 2018-08-21 17:04:56 -07:00
Bruno Oliveira
07a560ff24 Fix collection error when tests is specified with --doctest-modules
The problem was that _matchnodes would receive two items: [DoctestModule, Module]. It would then collect the first one, *cache it*, and fail to match against the name in the command line. Next, it would reuse the cached item (DoctestModule) instead of collecting the Module which would eventually find the "test" name on it.

Added the type of the node to the cache key to avoid this problem, although I'm not a big fan of caches that have different key types.

Fix #3843
2018-08-21 21:02:46 -03:00
Natan Lao
717775a1c6 Remove warning about #568 from documentation
The documentation (https://docs.pytest.org/en/latest/skipping.html) references
issue #568, which has since been fixed.
2018-08-21 16:57:33 -07:00
Bruno Oliveira
672f4bb5aa Improve CHANGELOG 2018-08-21 20:19:48 -03:00
Bruno Oliveira
f1079a8222 Merge pull request #3832 from Sup3rGeo/bugfix/capsys-with-cli-logging
Bugfix/capsys with cli logging (again)
2018-08-21 20:12:31 -03:00
Bruno Oliveira
044d2b8e6e Merge pull request #3838 from wimglenn/runresult_xfail
Support xfailed and xpassed outcomes in RunResult.
2018-08-20 20:01:51 -03:00
Sankt Petersbug
223eef6261 Fix '--show-capture=no' capture teardown logs
Add a check before printing teardown logs.

'print_teardown_sections' method does not check '--show-capture' option
value, and teardown logs are always printed.

Resolves: #3816
2018-08-20 15:01:21 -05:00
Bruno Oliveira
43657f252f Merge pull request #3830 from nicoddemus/capfd-fixture-capture
Fixtures during teardown can use capsys and capfd to get output from tests
2018-08-20 15:32:45 -03:00
Victor
70ebab3537 Renamed snap_global_capture to read_global_capture. 2018-08-20 17:48:14 +02:00
Ronny Pfannschmidt
d3bdfc704b Merge pull request #3839 from asottile/more_flexible
Use more flexible `language_version: python3`
2018-08-20 16:13:31 +02:00
Anthony Sottile
4de247cfa0 Use more flexible language_version: python3 2018-08-20 06:27:35 -07:00
Victor
d611b03589 Parametrized tests for capfd as well. Separated global capture test. 2018-08-20 12:23:59 +02:00
Anthony Sottile
308d789d92 Merge pull request #3835 from wimglenn/issue3833
more autodocs for pytester
2018-08-20 00:30:28 -07:00
wim glenn
539a22c750 Added support for xfailed and xpassed outcomes to the `pytester.RunResult.assert_outcomes` signature. 2018-08-20 01:24:19 -05:00
wim glenn
e4bea9068b end of line for this file, perhaps? 2018-08-19 23:39:10 -05:00
wim glenn
e620798d33 more autodocs for pytester 2018-08-19 23:21:45 -05:00
victor
7ea4992f16 Fixed linting. 2018-08-19 15:46:02 +02:00
victor
0564b52c0e Fixed integration with other modules/tests 2018-08-19 15:26:57 +02:00
victor
8b2c91836b Fixed activation and used just runtest_protocol hook 2018-08-19 14:30:50 +02:00
victor
9e382e8d29 Fixed test. 2018-08-19 14:29:57 +02:00
victor
2255892d65 Improved test to cover more cases. 2018-08-19 13:44:12 +02:00
victor
7d9b198f73 Refactoring: Separated suspend from snapping (stopped always snapping when suspending - solves bug but still missing tests), reorganized functions and context managers. 2018-08-19 02:32:36 +02:00
Bruno Oliveira
a6cdd0d9da Merge pull request #3831 from nicoddemus/merge-master-into-features
Merge master into features
2018-08-18 19:43:36 -03:00
Bruno Oliveira
c64a8c9c7f Merge remote-tracking branch 'upstream/master' into merge-master-into-features 2018-08-18 15:54:53 -03:00
Bruno Oliveira
f4c5994d27 Fixtures during teardown can use capsys and capfd to get output from tests
Fix #3033
2018-08-18 14:46:24 -03:00
Tyler Richard
c24c7e75e2 Added regression test for capfd in a fixture 2018-08-18 14:11:04 -03:00
Tyler Richard
273670b2a2 Fixes capfd so data is available after teardown. 2018-08-18 14:11:04 -03:00
Bruno Oliveira
28aff051ab Merge pull request #3822 from Sup3rGeo/bugfix/capsys-with-cli-logging
Bugfix/capsys with cli logging
2018-08-18 14:06:27 -03:00
Bruno Oliveira
29975e5b37 Merge pull request #3827 from Vlad-Shcherbina/funcfixtureinfo-type-hints
Replace broken type annotations with type comments
2018-08-18 12:54:47 -03:00
Bruno Oliveira
5cf7d1dba2 "suspend" method of capture fixture private
Also change the context-manager to global_and_fixture_disabled to
better convey its meaning
2018-08-18 11:38:08 -03:00
Bruno Oliveira
2fe824b8c4 Merge pull request #3821 from nicoddemus/release-3.7.2
Preparing release version 3.7.2
2018-08-18 11:18:18 -03:00
Bruno Oliveira
f674217c43 Moved dummy_context_manager to compat module 2018-08-18 11:15:58 -03:00
Bruno Oliveira
9f7345d663 Avoid leaving a reference to the last item on CaptureManager 2018-08-18 11:08:03 -03:00
victor
eb2d074530 Black changes. 2018-08-18 14:27:09 +02:00
victor
9fa7745795 Refactor, tests passing. 2018-08-18 13:40:08 +02:00
victor
14db2f91ba Fixed global not called if no capsys fixture. Using now capsys context manager as well. 2018-08-18 12:16:47 +02:00
Vlad Shcherbina
c3e494f6cf Replace broken type annotations with type comments
Fixes #3826.
2018-08-18 01:05:30 +03:00
Victor
090f67a980 Refactored implementation and updated tests. 2018-08-17 13:41:26 +02:00
Victor
3059bfb1b3 Update test with another problem. 2018-08-17 13:00:27 +02:00
Victor
e391c47ed8 Update capture suspend test for logging. 2018-08-17 00:44:15 +02:00
Victor
f66764e1c0 Added changelog and updated AUTHORS. 2018-08-17 00:33:56 +02:00
Bruno Oliveira
e0b088b52e Changelog tweaks 2018-08-16 19:32:41 -03:00
Bruno Oliveira
e5a3c870b4 Preparing release version 3.7.2 2018-08-16 22:29:00 +00:00
Victor
2b71cb9c38 Added activation/deactivation of capture fixture in logging emit. 2018-08-17 00:26:12 +02:00
Victor
da9d814da4 Added test. 2018-08-17 00:20:51 +02:00
Ronny Pfannschmidt
7d4c4c66d4 Merge pull request #3805 from asottile/cause_cycles
Fix traceback reporting for exceptions with `__cause__` cycles.
2018-08-16 07:16:51 +02:00
Ronny Pfannschmidt
939a792c41 Merge pull request #3798 from jonozzz/fix-3751
Fix #3751
2018-08-16 06:52:16 +02:00
Anthony Sottile
17644ff285 Fix traceback reporting for exceptions with __cause__ cycles. 2018-08-15 18:15:07 -07:00
Bruno Oliveira
64faa41d06 Merge pull request #3802 from jonozzz/fix-3768
Fix test collection from packages mixed with directories. #3768 and #3789
2018-08-15 21:42:25 -03:00
Anthony Sottile
ca1bb9a3a1 Merge pull request #3815 from sankt-petersbug/fix-3671
Fix #3671 - `filterwarnings` Is an Unregistered Marker
2018-08-15 17:07:46 -07:00
Sankt Petersbug
78ef531420 corrected the position of myname 2018-08-14 20:33:55 -05:00
Sankt Petersbug
212ee450b7 simplified test function 2018-08-14 20:29:42 -05:00
Sankt Petersbug
c1c08852f9 lint checks 2018-08-14 19:54:51 -05:00
Sankt Petersbug
e06a077ac2 added changelog 2018-08-14 16:16:37 -05:00
Sankt Petersbug
cb77e65c97 updated AUTHORS 2018-08-14 16:16:25 -05:00
Sankt Petersbug
6367f0f5f1 fix filterwarnings mark not registered 2018-08-14 16:13:15 -05:00
Daniel Hahler
b88e09a697 Merge pull request #3548 from blueyed/fix-docs
tox: clean up docs target
2018-08-14 15:22:46 +02:00
Ronny Pfannschmidt
68bbd42213 Merge pull request #3795 from nicoddemus/changelog-3774
Add CHANGELOG for issue #3774, missing from PR #3780
2018-08-14 09:32:20 +02:00
Ronny Pfannschmidt
22ee2093b8 Merge pull request #3801 from nicoddemus/improve-warning-addoption
Improve warning messages when addoption is called with string as `type`
2018-08-14 09:30:17 +02:00
Anthony Sottile
87a99275fb Merge pull request #3807 from anowlcalledjosh/metafunc-config-doc
Unhide documentation for metafunc.config
2018-08-13 15:32:43 -07:00
Josh Holland
abbd7c30a4 Unhide documentation for metafunc.config
Fixes #3746.
2018-08-11 20:48:55 +01:00
Bruno Oliveira
abae60c8d0 Add CHANGELOG entries 2018-08-10 22:04:42 -03:00
turturica
e92893ed24 Add test for packages mixed with modules. 2018-08-10 17:29:30 -07:00
Bruno Oliveira
27b5435a40 Fix docs formatting and improve test a bit 2018-08-10 18:19:07 -03:00
turturica
50db718a6a Add a test description. 2018-08-10 13:57:29 -07:00
turturica
bfd0addaeb Fix test collection from packages mixed with directories. #3768 and #3789 2018-08-10 12:56:08 -07:00
Bruno Oliveira
be11d3e195 Improve warning messages when addoption is called with string as type
Encountered the warning myself and to me the message was not clear about
what should be done to fix the warning
2018-08-10 12:49:06 -03:00
turturica
266f05c4c4 Fix #3751 2018-08-09 18:28:22 -07:00
turturica
d0bd01beca Collect any tests from a package's __init__.py 2018-08-09 18:06:38 -07:00
Bruno Oliveira
220288ac77 Add CHANGELOG for issue #3774, missing from PR #3780 2018-08-09 12:33:02 -03:00
Bruno Oliveira
4d8903fd0b Merge pull request #3780 from nicoddemus/mock-integration-fix
Fix issue where fixtures would lose the decorated functionality
2018-08-09 12:26:09 -03:00
Bruno Oliveira
67106f056b Use a custom holder class so we can be sure __pytest_wrapper__ was set by us 2018-08-09 09:22:00 -03:00
Ronny Pfannschmidt
5d3c5123f8 Merge pull request #3792 from decisio/pr-3788-fix-teardown-exception
Pr 3788 fix teardown exception
2018-08-09 06:53:22 +02:00
Bruno Oliveira
5f97711377 Merge pull request #3787 from hsoft/no-plugin-autoload
Add option to disable plugin auto-loading
2018-08-08 21:30:50 -03:00
Bruno Oliveira
74d9f56d0f Improve CHANGELOG a bit 2018-08-08 21:24:14 -03:00
Wes Thomas
051db6a33d Trimming Trailing Whitespace 2018-08-08 18:18:18 -05:00
Wes Thomas
aa358433b0 Fix AttributeError bug in TestCaseFunction.teardown by creating TestCaseFunction._testcase as attribute of class with a None default. 2018-08-08 18:13:21 -05:00
Virgil Dupras
126896f69d Add option to disable plugin auto-loading
If `PYTEST_DISABLE_PLUGIN_AUTOLOAD` is set, disable auto-loading of
plugins through setuptools entrypoints. Only plugins that have been
explicitly specified are loaded.

ref #3784.
2018-08-07 13:16:28 -04:00
Bruno Oliveira
e723069165 Merge pull request #3771 from nicoddemus/package-infinite-recursion-bug
Fix infinite recursion collection bug with pytest_ignore_collect hook
2018-08-06 10:09:31 -03:00
Bruno Oliveira
855fd17014 Merge pull request #3779 from nicoddemus/changelog-title
Add a changelog blurb and title, similar to tox
2018-08-05 18:03:57 -03:00
Bruno Oliveira
d11781920b Merge pull request #3782 from nicoddemus/pytest-non-functions
Only consider actual functions when collecting hooks
2018-08-05 09:07:01 -03:00
Bruno Oliveira
2c0d2eef40 Only consider actual functions when considering hooks
Fix #3775
2018-08-04 16:37:07 -03:00
Bruno Oliveira
ef8ec01e39 Fix issue where fixtures would lose the decorated functionality
Fix #3774
2018-08-04 15:14:00 -03:00
Bruno Oliveira
0a1c2a7ca1 Add a changelog blurb and title, similar to tox 2018-08-04 13:15:20 -03:00
Bruno Oliveira
fe0a76e1a6 Fix recursion bug if a pytest_ignore_collect returns False instead of None 2018-08-03 15:40:33 -03:00
Bruno Oliveira
dcafb8c48c Add example for package recursion bug 2018-08-03 15:40:33 -03:00
Bruno Oliveira
a76cc8f8c4 Add changelog for #3742
This was missing from PR #3751
2018-08-02 15:28:26 -03:00
Bruno Oliveira
4d2fa581e1 Merge pull request #3769 from nicoddemus/release-3.7.1
Preparing release version 3.7.1
2018-08-02 15:21:48 -03:00
Bruno Oliveira
f7a3f45a18 Preparing release version 3.7.1 2018-08-02 12:04:39 +00:00
Daniel Hahler
dff7b203f7 tox: clean up docs target 2018-08-02 13:07:03 +02:00
Anthony Sottile
4705fd2bbe Merge pull request #3765 from asottile/require_changelog_rst
Enforce that changelog files are .rst
2018-08-01 23:47:09 -07:00
Ronny Pfannschmidt
ca0476953e Merge pull request #3751 from nicoddemus/collect-file-bug
Workaround for #3742
2018-08-02 07:35:46 +02:00
Ronny Pfannschmidt
7e92930fa9 Merge pull request #3764 from asottile/fix_3763
Fix `TypeError` when the assertion message is `bytes` in python 3.
2018-08-02 07:19:51 +02:00
Ronny Pfannschmidt
33769d0328 Merge pull request #3754 from nicoddemus/fix-function-call-warning
Refactor direct fixture call warning to avoid incompatibility with plugins
2018-08-02 07:17:15 +02:00
Bruno Oliveira
5db2e6c7a1 Merge pull request #3761 from nicoddemus/numpy-recursion-error
Fix recursion in pytest.approx() with arrays in numpy<1.13
2018-08-01 23:40:30 -03:00
Bruno Oliveira
804fc4063a Merge pull request #3741 from kalekundert/approx_misc_tweaks
Miscellaneous improvements to approx()
2018-08-01 23:40:21 -03:00
Bruno Oliveira
82a2174867 Fix typo in CHANGELOG 2018-08-01 20:11:16 -03:00
Anthony Sottile
a80e031c62 Enforce that changelog files are .rst 2018-08-01 15:22:43 -07:00
Anthony Sottile
452e5c1cf0 Fix TypeError when the assertion message is bytes in python 3. 2018-08-01 15:09:25 -07:00
Bruno Oliveira
c6b11b9f62 Refactor direct fixture call warning to avoid incompatibility with plugins
This refactors the code so we have the real function object right during
collection. This avoids having to unwrap it later and lose attached information
such as "async" functions.

Fix #3747
2018-08-01 16:38:43 -03:00
Kale Kundert
b8255308d6 Make the infinite-recusrion fix more explicit.
So we remember what happened and don't accidentally regress in the
future.
2018-08-01 12:11:03 -07:00
Bruno Oliveira
a5c0fb7f6b Rename recursive_map -> _recursive_list_map as requested in review 2018-08-01 15:17:58 -03:00
Bruno Oliveira
f25683354e Merge pull request #3760 from RonnyPfannschmidt/fix-3757-pin-pathlib
fix #3757 by pinning to pathlib2 that supports __fspath__
2018-08-01 09:44:30 -03:00
Bruno Oliveira
7d13599ba1 Fix recursion in pytest.approx() with arrays in numpy<1.13 2018-08-01 08:04:09 -03:00
Bruno Oliveira
43664d7841 Use ids for parametrized values in test_expected_value_type_error 2018-08-01 07:34:08 -03:00
Bruno Oliveira
2a2f888909 Move recursive_map from local to free function 2018-08-01 07:30:40 -03:00
Bruno Oliveira
ad5ddaf55a Simplify is_numpy_array as suggested in review 2018-08-01 07:28:39 -03:00
Bruno Oliveira
4588130c1e Merge pull request #3756 from RonnyPfannschmidt/fix-3745
fix #3745 - display absolute cache_dir if necessary
2018-08-01 07:09:19 -03:00
Bruno Oliveira
5003bae0de Fix 'at' string for non-numeric messages in approx() 2018-08-01 07:07:37 -03:00
Bruno Oliveira
6e32a1f73d Use parametrize in repr test for nd arrays 2018-08-01 07:04:25 -03:00
Bruno Oliveira
611d254ed5 Improve error checking messages: add position and use pprint 2018-08-01 07:01:00 -03:00
Ronny Pfannschmidt
57a8f208bc fix #3757 by pinning to pathlib2 that supports __fspath__ 2018-08-01 11:45:39 +02:00
Ronny Pfannschmidt
fcdc1d867e fix #3745 - display absolute cache_dir if necessary 2018-08-01 08:25:37 +02:00
Bruno Oliveira
098dca3a9f Use {!r} for a few other messages as well 2018-07-31 21:14:51 -03:00
Bruno Oliveira
8e2ed76227 Create appropriate CHANGELOG entries 2018-07-31 21:11:26 -03:00
Bruno Oliveira
bf7c188cc0 Improve error message for invalid types passed to pytest.approx()
* Hide the internal traceback
* Use !r representation instead of !s (the default for {} formatting)
2018-07-31 21:08:24 -03:00
Bruno Oliveira
8c9efd8608 Only call _collectfile on package instances
As discussed in #3751, this feels like a hack, pushing it only so we can
see how it fares on CI and if there are better solutions out there
2018-07-31 19:06:30 -03:00
Bruno Oliveira
e1ad1a14af Add example script and failure for #3742 2018-07-31 17:50:55 -03:00
Kale Kundert
327fe4cfcc Update the changelog. 2018-07-31 11:40:02 -07:00
Kale Kundert
d02491931a Fix the unused import. 2018-07-31 11:33:46 -07:00
Kale Kundert
032db159c9 Let black reformat the code... 2018-07-31 11:23:23 -07:00
Kale Kundert
cd2085ee71 approx(): Detect type errors earlier. 2018-07-31 00:26:35 -07:00
Kale Kundert
ad305e71d7 Improve docstrings for Approx classes. 2018-07-30 23:26:57 -07:00
Kale Kundert
7d8688d54b Reflect dimension in approx repr for numpy arrays. 2018-07-30 23:23:17 -07:00
Bruno Oliveira
253419316c Merge pull request #3738 from nicoddemus/release-3.7.0
Release 3.7.0
2018-07-30 20:38:22 -03:00
266 changed files with 18296 additions and 7601 deletions

View File

@@ -1,4 +1,18 @@
[run]
omit =
# standlonetemplate is read dynamically and tested by test_genscript
*standalonetemplate.py
include =
src/*
testing/*
*/lib/python*/site-packages/_pytest/*
*/lib/python*/site-packages/pytest.py
*/pypy*/site-packages/_pytest/*
*/pypy*/site-packages/pytest.py
*\Lib\site-packages\_pytest\*
*\Lib\site-packages\pytest.py
parallel = 1
branch = 1
[paths]
source = src/
*/lib/python*/site-packages/
*/pypy*/site-packages/
*\Lib\site-packages\

2
.gitattributes vendored
View File

@@ -1 +1 @@
CHANGELOG merge=union
*.bat text eol=crlf

View File

@@ -1,8 +1,10 @@
<!--
Thanks for submitting an issue!
Here's a quick checklist in what to include:
Here's a quick checklist for what to provide:
-->
- [ ] Include a detailed description of the bug or suggestion
- [ ] `pip list` of the virtual environment you are using
- [ ] a detailed description of the bug or suggestion
- [ ] output of `pip list` from the virtual environment you are using
- [ ] pytest and operating system versions
- [ ] Minimal example if possible
- [ ] minimal example if possible

View File

@@ -1,9 +1,11 @@
<!--
Thanks for submitting a PR, your contribution is really appreciated!
Here's a quick checklist that should be present in PRs (you can delete this text from the final description, this is
just a guideline):
Here's a quick checklist that should be present in PRs.
(please delete this text from the final description, this is just a guideline)
-->
- [ ] Create a new changelog file in the `changelog` folder, with a name like `<ISSUE NUMBER>.<TYPE>.rst`. See [changelog/README.rst](/changelog/README.rst) for details.
- [ ] Create a new changelog file in the `changelog` folder, with a name like `<ISSUE NUMBER>.<TYPE>.rst`. See [changelog/README.rst](https://github.com/pytest-dev/pytest/blob/master/changelog/README.rst) for details.
- [ ] Target the `master` branch for bug fixes, documentation updates and trivial changes.
- [ ] Target the `features` branch for new features and removals/deprecations.
- [ ] Include documentation when adding new features.

2
.github/config.yml vendored Normal file
View File

@@ -0,0 +1,2 @@
rtd:
project: pytest

10
.gitignore vendored
View File

@@ -24,6 +24,7 @@ src/_pytest/_version.py
.eggs/
doc/*/_build
doc/*/.doctrees
build/
dist/
*.egg-info
@@ -35,6 +36,15 @@ env/
.cache
.pytest_cache
.coverage
.coverage.*
coverage.xml
.ropeproject
.idea
.hypothesis
.pydevproject
.project
.settings
.vscode
# generated by pip
pip-wheel-metadata/

View File

@@ -1,32 +1,43 @@
exclude: doc/en/example/py2py3/test_py2.py
repos:
- repo: https://github.com/ambv/black
rev: 18.6b4
- repo: https://github.com/python/black
rev: 19.3b0
hooks:
- id: black
args: [--safe, --quiet]
language_version: python3.6
language_version: python3
- repo: https://github.com/asottile/blacken-docs
rev: v0.2.0
rev: v0.5.0
hooks:
- id: blacken-docs
additional_dependencies: [black==18.6b4]
language_version: python3.6
additional_dependencies: [black==19.3b0]
language_version: python3
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v1.3.0
rev: v2.1.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: debug-statements
exclude: _pytest/debugging.py
- id: flake8
- repo: https://github.com/asottile/pyupgrade
rev: v1.2.0
language_version: python3
- repo: https://gitlab.com/pycqa/flake8
rev: 3.7.7
hooks:
- id: pyupgrade
- id: flake8
language_version: python3
- repo: https://github.com/asottile/reorder_python_imports
rev: v1.4.0
hooks:
- id: reorder-python-imports
args: ['--application-directories=.:src']
- repo: https://github.com/asottile/pyupgrade
rev: v1.15.0
hooks:
- id: pyupgrade
args: [--keep-percent-format]
- repo: https://github.com/pre-commit/pygrep-hooks
rev: v1.0.0
rev: v1.3.0
hooks:
- id: rst-backticks
- repo: local
@@ -37,4 +48,23 @@ repos:
files: ^(CHANGELOG.rst|HOWTORELEASE.rst|README.rst|changelog/.*)$
language: python
additional_dependencies: [pygments, restructuredtext_lint]
python_version: python3.6
- id: changelogs-rst
name: changelog filenames
language: fail
entry: 'changelog files must be named ####.(feature|bugfix|doc|deprecation|removal|vendor|trivial).rst'
exclude: changelog/(\d+\.(feature|bugfix|doc|deprecation|removal|vendor|trivial).rst|README.rst|_template.rst)
files: ^changelog/
- id: py-deprecated
name: py library is deprecated
language: pygrep
entry: >
(?x)\bpy\.(
_code\.|
builtin\.|
code\.|
io\.(BytesIO|saferepr)|
path\.local\.sysfind|
process\.|
std\.
)
types: [python]

View File

@@ -1,53 +1,103 @@
sudo: false
language: python
dist: xenial
stages:
- linting
- test
- baseline
- name: test
if: repo = pytest-dev/pytest AND tag IS NOT present
- name: deploy
if: repo = pytest-dev/pytest AND tag IS present
python:
- '3.6'
install:
- pip install --upgrade --pre tox
python: '3.7'
cache: false
env:
matrix:
# coveralls is not listed in tox's envlist, but should run in travis
- TOXENV=coveralls
# note: please use "tox --listenvs" to populate the build matrix below
# please remove the linting env in all cases
- TOXENV=py27
- TOXENV=py34
- TOXENV=py36
- TOXENV=py27-pexpect
- TOXENV=py27-xdist
- TOXENV=py27-trial
- TOXENV=py27-numpy
- TOXENV=py27-pluggymaster
- TOXENV=py36-pexpect
- TOXENV=py36-xdist
- TOXENV=py36-trial
- TOXENV=py36-numpy
- TOXENV=py36-pluggymaster
- TOXENV=py27-nobyte
- TOXENV=doctesting
- TOXENV=docs
global:
- PYTEST_ADDOPTS=-vv
install:
- python -m pip install --upgrade --pre tox
jobs:
include:
- env: TOXENV=pypy
python: 'pypy-5.4'
- env: TOXENV=py35
python: '3.5'
- env: TOXENV=py36-freeze
python: '3.6'
# OSX tests - first (in test stage), since they are the slower ones.
- &test-macos
# NOTE: (tests with) pexpect appear to be buggy on Travis,
# at least with coverage.
# Log: https://travis-ci.org/pytest-dev/pytest/jobs/500358864
os: osx
osx_image: xcode10.1
language: generic
# Coverage for:
# - py2 with symlink in test_cmdline_python_package_symlink.
env: TOXENV=py27-xdist PYTEST_COVERAGE=1
before_install:
- python -V
- test $(python -c 'import sys; print("%d%d" % sys.version_info[0:2])') = 27
- <<: *test-macos
env: TOXENV=py37-xdist
before_install:
- which python3
- python3 -V
- ln -sfn "$(which python3)" /usr/local/bin/python
- python -V
- test $(python -c 'import sys; print("%d%d" % sys.version_info[0:2])') = 37
# Full run of latest (major) supported versions, without xdist.
- env: TOXENV=py27
python: '2.7'
- env: TOXENV=py37
python: '3.7'
sudo: required
dist: xenial
# Coverage tracking is slow with pypy, skip it.
- env: TOXENV=pypy-xdist
python: 'pypy'
- env: TOXENV=pypy3-xdist
python: 'pypy3'
- env: TOXENV=py34-xdist
python: '3.4'
- env: TOXENV=py35-xdist
python: '3.5'
# Coverage for:
# - pytester's LsofFdLeakChecker
# - TestArgComplete (linux only)
# - numpy
# Empty PYTEST_ADDOPTS to run this non-verbose.
- env: TOXENV=py37-lsof-numpy-xdist PYTEST_COVERAGE=1 PYTEST_ADDOPTS=
# Specialized factors for py27.
- env: TOXENV=py27-nobyte-numpy-xdist
python: '2.7'
- env: TOXENV=py27-pluggymaster-xdist
python: '2.7'
# Specialized factors for py37.
# Coverage for:
# - test_sys_breakpoint_interception (via pexpect).
- env: TOXENV=py37-pexpect,py37-twisted PYTEST_COVERAGE=1
- env: TOXENV=py37-pluggymaster-xdist
- env: TOXENV=py37-freeze
# Jobs only run via Travis cron jobs (currently daily).
- env: TOXENV=py38-xdist
python: '3.8-dev'
if: type = cron
- stage: baseline
# Coverage for:
# - _pytest.unittest._handle_skip (via pexpect).
env: TOXENV=py27-pexpect,py27-twisted PYTEST_COVERAGE=1
python: '2.7'
# Use py36 here for faster baseline.
- env: TOXENV=py36-xdist
python: '3.6'
- env: TOXENV=linting,docs,doctesting PYTEST_COVERAGE=1
cache:
directories:
- $HOME/.cache/pre-commit
- stage: deploy
python: '3.6'
env:
install: pip install -U setuptools setuptools_scm
script: skip
deploy:
@@ -60,17 +110,40 @@ jobs:
on:
tags: true
repo: pytest-dev/pytest
- stage: linting
python: '3.6'
env:
install:
- pip install pre-commit
- pre-commit install-hooks
script:
- pre-commit run --all-files
matrix:
allow_failures:
- python: '3.8-dev'
env: TOXENV=py38-xdist
before_script:
- |
# Do not (re-)upload coverage with cron runs.
if [[ "$TRAVIS_EVENT_TYPE" = cron ]]; then
PYTEST_COVERAGE=0
fi
- |
if [[ "$PYTEST_COVERAGE" = 1 ]]; then
export COVERAGE_FILE="$PWD/.coverage"
export COVERAGE_PROCESS_START="$PWD/.coveragerc"
export _PYTEST_TOX_COVERAGE_RUN="coverage run -m"
export _PYTEST_TOX_EXTRA_DEP=coverage-enable-subprocess
fi
script: tox --recreate
after_success:
- |
if [[ "$PYTEST_COVERAGE" = 1 ]]; then
set -e
# Add last TOXENV to $PATH.
PATH="$PWD/.tox/${TOXENV##*,}/bin:$PATH"
coverage combine
coverage xml
coverage report -m
bash <(curl -s https://codecov.io/bash) -Z -X gcov -X coveragepy -X search -X xcode -X gcovout -X fix -f coverage.xml -n $TOXENV-$TRAVIS_OS_NAME
fi
notifications:
irc:
channels:
@@ -80,7 +153,3 @@ notifications:
skip_join: true
email:
- pytest-commit@python.org
cache:
directories:
- $HOME/.cache/pip
- $HOME/.cache/pre-commit

41
AUTHORS
View File

@@ -6,20 +6,29 @@ Contributors include::
Aaron Coleman
Abdeali JK
Abhijeet Kasurde
Adam Johnson
Adam Uhlir
Ahn Ki-Wook
Alan Velasco
Alexander Johnson
Alexei Kozlenok
Allan Feldman
Aly Sivji
Anatoly Bubenkoff
Anders Hovmöller
Andras Mitzki
Andras Tim
Andrea Cimatoribus
Andreas Zeidler
Andrey Paramonov
Andrzej Ostrowski
Andy Freeland
Anthon van der Neut
Anthony Shaw
Anthony Sottile
Anton Lodder
Antony Lee
Arel Cordero
Armin Rigo
Aron Coyle
Aron Curzon
@@ -43,10 +52,15 @@ Charles Cloud
Charnjit SiNGH (CCSJ)
Chris Lamb
Christian Boelsen
Christian Fetzer
Christian Theunert
Christian Tismer
Christopher Gilling
Christopher Dignam
CrazyMerlyn
Cyrus Maden
Damian Skrzypczak
Dhiren Serai
Daniel Grana
Daniel Hahler
Daniel Nuri
@@ -55,6 +69,7 @@ Danielle Jenkins
Dave Hunt
David Díaz-Barquero
David Mohr
David Szotten
David Vierra
Daw-Ran Liou
Denis Kirisov
@@ -71,6 +86,8 @@ Endre Galaczi
Eric Hunsberger
Eric Siegerman
Erik M. Bray
Fabien Zarifian
Fabio Zadrozny
Feng Ma
Florian Bruhin
Floris Bruynooghe
@@ -89,7 +106,9 @@ Hugo van Kemenade
Hui Wang (coldnight)
Ian Bicking
Ian Lesperance
Ilya Konstantinov
Ionuț Turturică
Iwan Briquemont
Jaap Broekhuizen
Jan Balster
Janne Vanhala
@@ -98,6 +117,7 @@ Javier Domingo Cansino
Javier Romero
Jeff Rackauckas
Jeff Widman
Jenni Rinker
John Eddie Ayson
John Towler
Jon Sonesen
@@ -105,6 +125,7 @@ Jonas Obrist
Jordan Guymon
Jordan Moldow
Jordan Speicher
Joseph Hunkeler
Joshua Bronson
Jurko Gospodnetić
Justyna Janczyszyn
@@ -114,6 +135,8 @@ Katerina Koukiou
Kevin Cox
Kodi B. Arfer
Kostis Anagnostopoulos
Kristoffer Nordström
Kyle Altendorf
Lawrence Mitchell
Lee Kamentsky
Lev Maximov
@@ -148,18 +171,24 @@ Michael Droettboom
Michael Seifert
Michal Wajszczuk
Mihai Capotă
Mike Hoyle (hoylemd)
Mike Lundy
Miro Hrončok
Nathaniel Waisbrot
Ned Batchelder
Neven Mundar
Nicholas Devenish
Nicholas Murphy
Niclas Olofsson
Nicolas Delaby
Nikolay Kondratyev
Oleg Pidsadnyi
Oleg Sushchenko
Oliver Bestwalter
Omar Kohl
Omer Hadari
Ondřej Súkup
Oscar Benjamin
Patrick Hayes
Paweł Adamczak
Pedro Algarvio
@@ -174,6 +203,7 @@ Raphael Pierzina
Raquel Alegre
Ravi Chandra
Roberto Polli
Roland Puntaier
Romain Dorgueil
Roman Bolshakov
Ronny Pfannschmidt
@@ -182,6 +212,7 @@ Russel Winder
Ryan Wooden
Samuel Dion-Girardeau
Samuele Pedroni
Sankt Petersbug
Segev Finer
Serhii Mozghovyi
Simon Gomizelj
@@ -192,7 +223,9 @@ Stefan Zimmermann
Stefano Taschini
Steffen Allner
Stephan Obermann
Sven-Hendrik Haase
Tadek Teleżyński
Takafumi Arakaki
Tarcisio Fischer
Tareq Alayan
Ted Xiao
@@ -201,19 +234,23 @@ Thomas Hisch
Tim Strazny
Tom Dalton
Tom Viner
Tomer Keren
Trevor Bekolay
Tyler Goodlet
Tzu-ping Chung
Vasily Kuznetsov
Victor Maryama
Victor Uriarte
Vidar T. Fauske
Virgil Dupras
Vitaly Lashmanov
Vlad Dragos
Volodymyr Piskun
Wil Cooley
William Lee
Wim Glenn
Wouter van Ackooy
Xuan Luong
Xuecong Liao
Zac Hatfield-Dodds
Zoltán Máté
Roland Puntaier
Allan Feldman

File diff suppressed because it is too large Load Diff

View File

@@ -166,10 +166,10 @@ Short version
#. Enable and install `pre-commit <https://pre-commit.com>`_ to ensure style-guides and code checks are followed.
#. Target ``master`` for bugfixes and doc changes.
#. Target ``features`` for new features or functionality changes.
#. Follow **PEP-8** for naming and `black <https://github.com/ambv/black>`_ for formatting.
#. Follow **PEP-8** for naming and `black <https://github.com/python/black>`_ for formatting.
#. Tests are run using ``tox``::
tox -e linting,py27,py36
tox -e linting,py27,py37
The test environments above are usually enough to cover most cases locally.
@@ -237,12 +237,12 @@ Here is a simple overview, with pytest-specific bits:
#. Run all the tests
You need to have Python 2.7 and 3.6 available in your system. Now
You need to have Python 2.7 and 3.7 available in your system. Now
running tests is as simple as issuing this command::
$ tox -e linting,py27,py36
$ tox -e linting,py27,py37
This command will run tests via the "tox" tool against Python 2.7 and 3.6
This command will run tests via the "tox" tool against Python 2.7 and 3.7
and also perform "lint" coding-style checks.
#. You can now edit your local working copy and run the tests again as necessary. Please follow PEP-8 for naming.
@@ -252,9 +252,9 @@ Here is a simple overview, with pytest-specific bits:
$ tox -e py27 -- --pdb
Or to only run tests in a particular test module on Python 3.6::
Or to only run tests in a particular test module on Python 3.7::
$ tox -e py36 -- testing/test_config.py
$ tox -e py37 -- testing/test_config.py
When committing, ``pre-commit`` will re-format the files if necessary.
@@ -280,6 +280,47 @@ Here is a simple overview, with pytest-specific bits:
base: features # if it's a feature
Writing Tests
----------------------------
Writing tests for plugins or for pytest itself is often done using the `testdir fixture <https://docs.pytest.org/en/latest/reference.html#testdir>`_, as a "black-box" test.
For example, to ensure a simple test passes you can write:
.. code-block:: python
def test_true_assertion(testdir):
testdir.makepyfile(
"""
def test_foo():
assert True
"""
)
result = testdir.runpytest()
result.assert_outcomes(failed=0, passed=1)
Alternatively, it is possible to make checks based on the actual output of the termal using
*glob-like* expressions:
.. code-block:: python
def test_true_assertion(testdir):
testdir.makepyfile(
"""
def test_foo():
assert False
"""
)
result = testdir.runpytest()
result.stdout.fnmatch_lines(["*assert False*", "*1 failed*"])
When choosing a file where to write a new test, take a look at the existing files and see if there's
one file which looks like a good fit. For example, a regression test about a bug in the ``--lf`` option
should go into ``test_cacheprovider.py``, given that this option is implemented in ``cacheprovider.py``.
If in doubt, go ahead and open a PR with your best guess and we can discuss this over the code.
Joining the Development Team
----------------------------

View File

@@ -28,10 +28,13 @@ taking a lot of time to make a new one.
#. After all tests pass and the PR has been approved, publish to PyPI by pushing the tag::
git tag <VERSION>
git push git@github.com:pytest-dev/pytest.git <VERSION>
Wait for the deploy to complete, then make sure it is `available on PyPI <https://pypi.org/project/pytest>`_.
#. Merge the PR into ``master``.
#. Send an email announcement with the contents from::
doc/en/announce/release-<VERSION>.rst
@@ -43,5 +46,3 @@ taking a lot of time to make a new one.
* testing-in-python@lists.idyll.org (only major/minor releases)
And announce it on `Twitter <https://twitter.com/>`_ with the ``#pytest`` hashtag.
#. After a minor/major release, merge ``release-X.Y.Z`` into ``master`` and push (or open a PR).

View File

@@ -1,6 +1,6 @@
The MIT License (MIT)
Copyright (c) 2004-2017 Holger Krekel and others
Copyright (c) 2004-2019 Holger Krekel and others
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in

View File

@@ -1,5 +1,5 @@
.. image:: http://docs.pytest.org/en/latest/_static/pytest1.png
:target: http://docs.pytest.org
.. image:: https://docs.pytest.org/en/latest/_static/pytest1.png
:target: https://docs.pytest.org/en/latest/
:align: center
:alt: pytest
@@ -15,17 +15,18 @@
.. image:: https://img.shields.io/pypi/pyversions/pytest.svg
:target: https://pypi.org/project/pytest/
.. image:: https://img.shields.io/coveralls/pytest-dev/pytest/master.svg
:target: https://coveralls.io/r/pytest-dev/pytest
.. image:: https://codecov.io/gh/pytest-dev/pytest/branch/master/graph/badge.svg
:target: https://codecov.io/gh/pytest-dev/pytest
:alt: Code coverage Status
.. image:: https://travis-ci.org/pytest-dev/pytest.svg?branch=master
:target: https://travis-ci.org/pytest-dev/pytest
.. image:: https://ci.appveyor.com/api/projects/status/mrgbjaua7t33pg6b?svg=true
:target: https://ci.appveyor.com/project/pytestbot/pytest
.. image:: https://dev.azure.com/pytest-dev/pytest/_apis/build/status/pytest-CI?branchName=master
:target: https://dev.azure.com/pytest-dev/pytest
.. image:: https://img.shields.io/badge/code%20style-black-000000.svg
:target: https://github.com/ambv/black
:target: https://github.com/python/black
.. image:: https://www.codetriage.com/pytest-dev/pytest/badges/users.svg
:target: https://www.codetriage.com/pytest-dev/pytest
@@ -66,23 +67,23 @@ To execute it::
========================== 1 failed in 0.04 seconds ===========================
Due to ``pytest``'s detailed assertion introspection, only plain ``assert`` statements are used. See `getting-started <http://docs.pytest.org/en/latest/getting-started.html#our-first-test-run>`_ for more examples.
Due to ``pytest``'s detailed assertion introspection, only plain ``assert`` statements are used. See `getting-started <https://docs.pytest.org/en/latest/getting-started.html#our-first-test-run>`_ for more examples.
Features
--------
- Detailed info on failing `assert statements <http://docs.pytest.org/en/latest/assert.html>`_ (no need to remember ``self.assert*`` names);
- Detailed info on failing `assert statements <https://docs.pytest.org/en/latest/assert.html>`_ (no need to remember ``self.assert*`` names);
- `Auto-discovery
<http://docs.pytest.org/en/latest/goodpractices.html#python-test-discovery>`_
<https://docs.pytest.org/en/latest/goodpractices.html#python-test-discovery>`_
of test modules and functions;
- `Modular fixtures <http://docs.pytest.org/en/latest/fixture.html>`_ for
- `Modular fixtures <https://docs.pytest.org/en/latest/fixture.html>`_ for
managing small or parametrized long-lived test resources;
- Can run `unittest <http://docs.pytest.org/en/latest/unittest.html>`_ (or trial),
`nose <http://docs.pytest.org/en/latest/nose.html>`_ test suites out of the box;
- Can run `unittest <https://docs.pytest.org/en/latest/unittest.html>`_ (or trial),
`nose <https://docs.pytest.org/en/latest/nose.html>`_ test suites out of the box;
- Python 2.7, Python 3.4+, PyPy 2.3, Jython 2.5 (untested);
@@ -92,7 +93,7 @@ Features
Documentation
-------------
For full documentation, including installation, tutorials and PDF documents, please see http://docs.pytest.org.
For full documentation, including installation, tutorials and PDF documents, please see https://docs.pytest.org/en/latest/.
Bugs/Requests
@@ -104,13 +105,13 @@ Please use the `GitHub issue tracker <https://github.com/pytest-dev/pytest/issue
Changelog
---------
Consult the `Changelog <http://docs.pytest.org/en/latest/changelog.html>`__ page for fixes and enhancements of each version.
Consult the `Changelog <https://docs.pytest.org/en/latest/changelog.html>`__ page for fixes and enhancements of each version.
License
-------
Copyright Holger Krekel and others, 2004-2018.
Copyright Holger Krekel and others, 2004-2019.
Distributed under the terms of the `MIT`_ license, pytest is free and open source software.

View File

@@ -1,53 +0,0 @@
environment:
COVERALLS_REPO_TOKEN:
secure: 2NJ5Ct55cHJ9WEg3xbSqCuv0rdgzzb6pnzOIG5OkMbTndw3wOBrXntWFoQrXiMFi
# this is pytest's token in coveralls.io, encrypted
# using pytestbot account as detailed here:
# https://www.appveyor.com/docs/build-configuration#secure-variables
matrix:
# coveralls is not in the default env list
- TOXENV: "coveralls"
# note: please use "tox --listenvs" to populate the build matrix below
- TOXENV: "linting"
- TOXENV: "py27"
- TOXENV: "py34"
- TOXENV: "py35"
- TOXENV: "py36"
- TOXENV: "py37"
# - TOXENV: "pypy" reenable when we are able to provide a scandir wheel or build scandir
- TOXENV: "py27-pexpect"
- TOXENV: "py27-xdist"
- TOXENV: "py27-trial"
- TOXENV: "py27-numpy"
- TOXENV: "py27-pluggymaster"
- TOXENV: "py36-pexpect"
- TOXENV: "py36-xdist"
- TOXENV: "py36-trial"
- TOXENV: "py36-numpy"
- TOXENV: "py36-pluggymaster"
- TOXENV: "py27-nobyte"
- TOXENV: "doctesting"
- TOXENV: "py36-freeze"
- TOXENV: "docs"
install:
- echo Installed Pythons
- dir c:\Python*
- if "%TOXENV%" == "pypy" call scripts\install-pypy.bat
- C:\Python36\python -m pip install --upgrade --pre tox
build: false # Not a C# project, build stuff at the test step instead.
test_script:
- call scripts\call-tox.bat
cache:
- '%LOCALAPPDATA%\pip\cache'
- '%USERPROFILE%\.cache\pre-commit'
# We don't deploy anything on tags with AppVeyor, we use Travis instead, so we
# might as well save resources
skip_tags: true

117
azure-pipelines.yml Normal file
View File

@@ -0,0 +1,117 @@
trigger:
- master
- features
variables:
PYTEST_ADDOPTS: "--junitxml=build/test-results/$(tox.env).xml -vv"
python.needs_vc: False
python.exe: "python"
COVERAGE_FILE: "$(Build.Repository.LocalPath)/.coverage"
COVERAGE_PROCESS_START: "$(Build.Repository.LocalPath)/.coveragerc"
PYTEST_COVERAGE: '0'
jobs:
- job: 'Test'
pool:
vmImage: "vs2017-win2016"
strategy:
matrix:
py27:
python.version: '2.7'
tox.env: 'py27'
py27-nobyte-lsof-numpy:
python.version: '2.7'
tox.env: 'py27-lsof-nobyte-numpy'
# Coverage for:
# - test_supports_breakpoint_module_global
# - test_terminal_reporter_writer_attr (without xdist)
# - "if write" branch in _pytest.assertion.rewrite
# - numpy
# - pytester's LsofFdLeakChecker (being skipped)
PYTEST_COVERAGE: '1'
py27-twisted:
python.version: '2.7'
tox.env: 'py27-twisted'
python.needs_vc: True
py27-pluggymaster-xdist:
python.version: '2.7'
tox.env: 'py27-pluggymaster-xdist'
# Coverage for:
# - except-IOError in _attempt_to_close_capture_file for py2.
# Also seen with py27-nobyte (using xdist), and py27-xdist.
# But no exception with py27-pexpect,py27-twisted,py27-numpy.
PYTEST_COVERAGE: '1'
pypy:
python.version: 'pypy2'
tox.env: 'pypy'
python.exe: 'pypy'
# NOTE: pypy3 fails to install pip currently due to an internal error.
# pypy3:
# python.version: 'pypy3'
# tox.env: 'pypy3'
# python.exe: 'pypy3'
py34-xdist:
python.version: '3.4'
tox.env: 'py34-xdist'
# Coverage for:
# - _pytest.compat._bytes_to_ascii
PYTEST_COVERAGE: '1'
py35-xdist:
python.version: '3.5'
tox.env: 'py35-xdist'
# Coverage for:
# - test_supports_breakpoint_module_global
PYTEST_COVERAGE: '1'
py36-xdist:
python.version: '3.6'
tox.env: 'py36-xdist'
py37:
python.version: '3.7'
tox.env: 'py37'
# Coverage for:
# - _py36_windowsconsoleio_workaround (with py36+)
# - test_request_garbage (no xdist)
PYTEST_COVERAGE: '1'
py37-linting/docs/doctesting:
python.version: '3.7'
tox.env: 'linting,docs,doctesting'
py37-twisted/numpy:
python.version: '3.7'
tox.env: 'py37-twisted,py37-numpy'
py37-pluggymaster-xdist:
python.version: '3.7'
tox.env: 'py37-pluggymaster-xdist'
maxParallel: 10
steps:
- task: UsePythonVersion@0
inputs:
versionSpec: '$(python.version)'
architecture: 'x64'
- script: choco install vcpython27
condition: eq(variables['python.needs_vc'], True)
displayName: 'Install VC for py27'
- script: $(python.exe) -m pip install --upgrade pip && $(python.exe) -m pip install tox
displayName: 'Install tox'
- script: |
call scripts/setup-coverage-vars.bat || goto :eof
$(python.exe) -m tox -e $(tox.env)
displayName: 'Run tests'
- task: PublishTestResults@2
inputs:
testResultsFiles: 'build/test-results/$(tox.env).xml'
testRunTitle: '$(tox.env)'
condition: succeededOrFailed()
- script: call scripts\upload-coverage.bat
displayName: 'Report and upload coverage'
condition: eq(variables['PYTEST_COVERAGE'], '1')
env:
PYTHON: $(python.exe)
CODECOV_TOKEN: $(CODECOV_TOKEN)
PYTEST_CODECOV_NAME: $(tox.env)

View File

@@ -5,7 +5,7 @@ if __name__ == "__main__":
import pytest # NOQA
import pstats
script = sys.argv[1:] if len(sys.argv) > 1 else "empty.py"
script = sys.argv[1:] if len(sys.argv) > 1 else ["empty.py"]
stats = cProfile.run("pytest.cmdline.main(%r)" % script, "prof")
p = pstats.Stats("prof")
p.strip_dirs()

View File

@@ -1,10 +1,7 @@
# 10000 iterations, just for relative comparison
# 2.7.5 3.3.2
# FilesCompleter 75.1109 69.2116
# FastFilesCompleter 0.7383 1.0760
import timeit
imports = [
@@ -19,4 +16,4 @@ run = 'fc("/d")'
if __name__ == "__main__":
print(timeit.timeit(run, setup=setup % imports[0], number=count))
print((timeit.timeit(run, setup=setup % imports[1], number=count)))
print(timeit.timeit(run, setup=setup % imports[1], number=count))

View File

@@ -1,4 +1,2 @@
import py
for i in range(1000):
py.builtin.exec_("def test_func_%d(): pass" % i)
exec("def test_func_%d(): pass" % i)

View File

@@ -1,4 +1,3 @@
import pytest

View File

@@ -1,6 +1,6 @@
from six.moves import range
import pytest
import pytest
SKIP = True

View File

@@ -14,7 +14,8 @@ Each file should be named like ``<ISSUE>.<TYPE>.rst``, where
* ``feature``: new user facing features, like new command-line options and new behavior.
* ``bugfix``: fixes a reported bug.
* ``doc``: documentation improvement, like rewording an entire session or adding missing docs.
* ``removal``: feature deprecation or removal.
* ``deprecation``: feature deprecation.
* ``removal``: feature removal.
* ``vendor``: changes in packages vendored in pytest.
* ``trivial``: fixing a small typo or internal change that might be noteworthy.

View File

@@ -13,6 +13,9 @@ PAPEROPT_letter = -D latex_paper_size=letter
ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) .
REGENDOC_ARGS := \
--normalize "/[ \t]+\n/\n/" \
--normalize "~\$$REGENDOC_TMPDIR~/home/sweet/project~" \
--normalize "~/path/to/example~/home/sweet/project~" \
--normalize "/in \d+.\d+ seconds/in 0.12 seconds/" \
--normalize "@/tmp/pytest-of-.*/pytest-\d+@PYTEST_TMPDIR@" \
--normalize "@pytest-(\d+)\\.[^ ,]+@pytest-\1.x.y@" \
@@ -38,8 +41,9 @@ help:
clean:
-rm -rf $(BUILDDIR)/*
regen: REGENDOC_FILES:=*.rst */*.rst
regen:
PYTHONDONTWRITEBYTECODE=1 PYTEST_ADDOPT=-pno:hypothesis COLUMNS=76 regendoc --update *.rst */*.rst ${REGENDOC_ARGS}
PYTHONDONTWRITEBYTECODE=1 PYTEST_ADDOPTS=-pno:hypothesis COLUMNS=76 regendoc --update ${REGENDOC_FILES} ${REGENDOC_ARGS}
html:
$(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html

View File

@@ -1,19 +1,17 @@
# flasky extensions. flasky pygments style based on tango style
from pygments.style import Style
from pygments.token import (
Keyword,
Name,
Comment,
String,
Error,
Number,
Operator,
Generic,
Whitespace,
Punctuation,
Other,
Literal,
)
from pygments.token import Comment
from pygments.token import Error
from pygments.token import Generic
from pygments.token import Keyword
from pygments.token import Literal
from pygments.token import Name
from pygments.token import Number
from pygments.token import Operator
from pygments.token import Other
from pygments.token import Punctuation
from pygments.token import String
from pygments.token import Whitespace
class FlaskyStyle(Style):

View File

@@ -6,6 +6,31 @@ Release announcements
:maxdepth: 2
release-4.4.2
release-4.4.1
release-4.4.0
release-4.3.1
release-4.3.0
release-4.2.1
release-4.2.0
release-4.1.1
release-4.1.0
release-4.0.2
release-4.0.1
release-4.0.0
release-3.10.1
release-3.10.0
release-3.9.3
release-3.9.2
release-3.9.1
release-3.9.0
release-3.8.2
release-3.8.1
release-3.8.0
release-3.7.4
release-3.7.3
release-3.7.2
release-3.7.1
release-3.7.0
release-3.6.4
release-3.6.3

View File

@@ -0,0 +1,43 @@
pytest-3.10.0
=======================================
The pytest team is proud to announce the 3.10.0 release!
pytest is a mature Python testing tool with more than a 2000 tests
against itself, passing on many different interpreters and platforms.
This release contains a number of bugs fixes and improvements, so users are encouraged
to take a look at the CHANGELOG:
https://docs.pytest.org/en/latest/changelog.html
For complete documentation, please visit:
https://docs.pytest.org/en/latest/
As usual, you can upgrade from pypi via:
pip install -U pytest
Thanks to all who contributed to this release, among them:
* Anders Hovmöller
* Andreu Vallbona Plazas
* Ankit Goel
* Anthony Sottile
* Bernardo Gomes
* Brianna Laugher
* Bruno Oliveira
* Daniel Hahler
* David Szotten
* Mick Koch
* Niclas Olofsson
* Palash Chatterjee
* Ronny Pfannschmidt
* Sven-Hendrik Haase
* Ville Skyttä
* William Jamir Silva
Happy testing,
The Pytest Development Team

View File

@@ -0,0 +1,24 @@
pytest-3.10.1
=======================================
pytest 3.10.1 has just been released to PyPI.
This is a bug-fix release, being a drop-in replacement. To upgrade::
pip install --upgrade pytest
The full changelog is available at https://docs.pytest.org/en/latest/changelog.html.
Thanks to all who contributed to this release, among them:
* Anthony Sottile
* Boris Feld
* Bruno Oliveira
* Daniel Hahler
* Fabien ZARIFIAN
* Jon Dufresne
* Ronny Pfannschmidt
Happy testing,
The pytest Development Team

View File

@@ -20,8 +20,7 @@ Thanks to all who contributed to this release, among them:
* Ondřej Súkup
* Ronny Pfannschmidt
* T.E.A de Souza
* Victor
* victor
* Victor Maryama
Happy testing,

View File

@@ -0,0 +1,21 @@
pytest-3.7.1
=======================================
pytest 3.7.1 has just been released to PyPI.
This is a bug-fix release, being a drop-in replacement. To upgrade::
pip install --upgrade pytest
The full changelog is available at http://doc.pytest.org/en/latest/changelog.html.
Thanks to all who contributed to this release, among them:
* Anthony Sottile
* Bruno Oliveira
* Kale Kundert
* Ronny Pfannschmidt
Happy testing,
The pytest Development Team

View File

@@ -0,0 +1,25 @@
pytest-3.7.2
=======================================
pytest 3.7.2 has just been released to PyPI.
This is a bug-fix release, being a drop-in replacement. To upgrade::
pip install --upgrade pytest
The full changelog is available at http://doc.pytest.org/en/latest/changelog.html.
Thanks to all who contributed to this release, among them:
* Anthony Sottile
* Bruno Oliveira
* Daniel Hahler
* Josh Holland
* Ronny Pfannschmidt
* Sankt Petersbug
* Wes Thomas
* turturica
Happy testing,
The pytest Development Team

View File

@@ -0,0 +1,32 @@
pytest-3.7.3
=======================================
pytest 3.7.3 has just been released to PyPI.
This is a bug-fix release, being a drop-in replacement. To upgrade::
pip install --upgrade pytest
The full changelog is available at http://doc.pytest.org/en/latest/changelog.html.
Thanks to all who contributed to this release, among them:
* Andrew Champion
* Anthony Sottile
* Bruno Oliveira
* Daniel Hahler
* Gandalf Saxe
* Jennifer Rinker
* Natan Lao
* Ondřej Súkup
* Ronny Pfannschmidt
* Sankt Petersbug
* Tyler Richard
* Victor Maryama
* Vlad Shcherbina
* turturica
* wim glenn
Happy testing,
The pytest Development Team

View File

@@ -0,0 +1,22 @@
pytest-3.7.4
=======================================
pytest 3.7.4 has just been released to PyPI.
This is a bug-fix release, being a drop-in replacement. To upgrade::
pip install --upgrade pytest
The full changelog is available at https://docs.pytest.org/en/latest/changelog.html.
Thanks to all who contributed to this release, among them:
* Anthony Sottile
* Bruno Oliveira
* Daniel Hahler
* Jiri Kuncar
* Steve Piercy
Happy testing,
The pytest Development Team

View File

@@ -0,0 +1,38 @@
pytest-3.8.0
=======================================
The pytest team is proud to announce the 3.8.0 release!
pytest is a mature Python testing tool with more than a 2000 tests
against itself, passing on many different interpreters and platforms.
This release contains a number of bugs fixes and improvements, so users are encouraged
to take a look at the CHANGELOG:
https://docs.pytest.org/en/latest/changelog.html
For complete documentation, please visit:
https://docs.pytest.org/en/latest/
As usual, you can upgrade from pypi via:
pip install -U pytest
Thanks to all who contributed to this release, among them:
* Anthony Sottile
* Bruno Oliveira
* CrazyMerlyn
* Daniel Hahler
* Fabio Zadrozny
* Jeffrey Rackauckas
* Ronny Pfannschmidt
* Virgil Dupras
* dhirensr
* hoefling
* wim glenn
Happy testing,
The Pytest Development Team

View File

@@ -0,0 +1,25 @@
pytest-3.8.1
=======================================
pytest 3.8.1 has just been released to PyPI.
This is a bug-fix release, being a drop-in replacement. To upgrade::
pip install --upgrade pytest
The full changelog is available at https://docs.pytest.org/en/latest/changelog.html.
Thanks to all who contributed to this release, among them:
* Ankit Goel
* Anthony Sottile
* Bruno Oliveira
* Daniel Hahler
* Maximilian Albert
* Ronny Pfannschmidt
* William Jamir Silva
* wim glenn
Happy testing,
The pytest Development Team

View File

@@ -0,0 +1,28 @@
pytest-3.8.2
=======================================
pytest 3.8.2 has just been released to PyPI.
This is a bug-fix release, being a drop-in replacement. To upgrade::
pip install --upgrade pytest
The full changelog is available at https://docs.pytest.org/en/latest/changelog.html.
Thanks to all who contributed to this release, among them:
* Ankit Goel
* Anthony Sottile
* Bruno Oliveira
* Daniel Hahler
* Denis Otkidach
* Harry Percival
* Jeffrey Rackauckas
* Jose Carlos Menezes
* Ronny Pfannschmidt
* Zac-HD
* iwanb
Happy testing,
The pytest Development Team

View File

@@ -0,0 +1,43 @@
pytest-3.9.0
=======================================
The pytest team is proud to announce the 3.9.0 release!
pytest is a mature Python testing tool with more than a 2000 tests
against itself, passing on many different interpreters and platforms.
This release contains a number of bugs fixes and improvements, so users are encouraged
to take a look at the CHANGELOG:
https://docs.pytest.org/en/latest/changelog.html
For complete documentation, please visit:
https://docs.pytest.org/en/latest/
As usual, you can upgrade from pypi via:
pip install -U pytest
Thanks to all who contributed to this release, among them:
* Andrea Cimatoribus
* Ankit Goel
* Anthony Sottile
* Ben Eyal
* Bruno Oliveira
* Daniel Hahler
* Jeffrey Rackauckas
* Jose Carlos Menezes
* Kyle Altendorf
* Niklas JQ
* Palash Chatterjee
* Ronny Pfannschmidt
* Thomas Hess
* Thomas Hisch
* Tomer Keren
* Victor Maryama
Happy testing,
The Pytest Development Team

View File

@@ -0,0 +1,20 @@
pytest-3.9.1
=======================================
pytest 3.9.1 has just been released to PyPI.
This is a bug-fix release, being a drop-in replacement. To upgrade::
pip install --upgrade pytest
The full changelog is available at https://docs.pytest.org/en/latest/changelog.html.
Thanks to all who contributed to this release, among them:
* Bruno Oliveira
* Ronny Pfannschmidt
* Thomas Hisch
Happy testing,
The pytest Development Team

View File

@@ -0,0 +1,23 @@
pytest-3.9.2
=======================================
pytest 3.9.2 has just been released to PyPI.
This is a bug-fix release, being a drop-in replacement. To upgrade::
pip install --upgrade pytest
The full changelog is available at https://docs.pytest.org/en/latest/changelog.html.
Thanks to all who contributed to this release, among them:
* Ankit Goel
* Anthony Sottile
* Bruno Oliveira
* Ronny Pfannschmidt
* Vincent Barbaresi
* ykantor
Happy testing,
The pytest Development Team

View File

@@ -0,0 +1,24 @@
pytest-3.9.3
=======================================
pytest 3.9.3 has just been released to PyPI.
This is a bug-fix release, being a drop-in replacement. To upgrade::
pip install --upgrade pytest
The full changelog is available at https://docs.pytest.org/en/latest/changelog.html.
Thanks to all who contributed to this release, among them:
* Andreas Profous
* Ankit Goel
* Anthony Sottile
* Bruno Oliveira
* Daniel Hahler
* Jon Dufresne
* Ronny Pfannschmidt
Happy testing,
The pytest Development Team

View File

@@ -0,0 +1,30 @@
pytest-4.0.0
=======================================
The pytest team is proud to announce the 4.0.0 release!
pytest is a mature Python testing tool with more than a 2000 tests
against itself, passing on many different interpreters and platforms.
This release contains a number of bugs fixes and improvements, so users are encouraged
to take a look at the CHANGELOG:
https://docs.pytest.org/en/latest/changelog.html
For complete documentation, please visit:
https://docs.pytest.org/en/latest/
As usual, you can upgrade from pypi via:
pip install -U pytest
Thanks to all who contributed to this release, among them:
* Bruno Oliveira
* Daniel Hahler
* Ronny Pfannschmidt
Happy testing,
The Pytest Development Team

View File

@@ -0,0 +1,23 @@
pytest-4.0.1
=======================================
pytest 4.0.1 has just been released to PyPI.
This is a bug-fix release, being a drop-in replacement. To upgrade::
pip install --upgrade pytest
The full changelog is available at https://docs.pytest.org/en/latest/changelog.html.
Thanks to all who contributed to this release, among them:
* Anthony Sottile
* Bruno Oliveira
* Daniel Hahler
* Michael D. Hoyle
* Ronny Pfannschmidt
* Slam
Happy testing,
The pytest Development Team

View File

@@ -0,0 +1,24 @@
pytest-4.0.2
=======================================
pytest 4.0.2 has just been released to PyPI.
This is a bug-fix release, being a drop-in replacement. To upgrade::
pip install --upgrade pytest
The full changelog is available at https://docs.pytest.org/en/latest/changelog.html.
Thanks to all who contributed to this release, among them:
* Anthony Sottile
* Bruno Oliveira
* Daniel Hahler
* Pedro Algarvio
* Ronny Pfannschmidt
* Tomer Keren
* Yash Todi
Happy testing,
The pytest Development Team

View File

@@ -0,0 +1,44 @@
pytest-4.1.0
=======================================
The pytest team is proud to announce the 4.1.0 release!
pytest is a mature Python testing tool with more than a 2000 tests
against itself, passing on many different interpreters and platforms.
This release contains a number of bugs fixes and improvements, so users are encouraged
to take a look at the CHANGELOG:
https://docs.pytest.org/en/latest/changelog.html
For complete documentation, please visit:
https://docs.pytest.org/en/latest/
As usual, you can upgrade from pypi via:
pip install -U pytest
Thanks to all who contributed to this release, among them:
* Adam Johnson
* Aly Sivji
* Andrey Paramonov
* Anthony Sottile
* Bruno Oliveira
* Daniel Hahler
* David Vo
* Hyunchel Kim
* Jeffrey Rackauckas
* Kanguros
* Nicholas Devenish
* Pedro Algarvio
* Randy Barlow
* Ronny Pfannschmidt
* Tomer Keren
* feuillemorte
* wim glenn
Happy testing,
The Pytest Development Team

View File

@@ -0,0 +1,27 @@
pytest-4.1.1
=======================================
pytest 4.1.1 has just been released to PyPI.
This is a bug-fix release, being a drop-in replacement. To upgrade::
pip install --upgrade pytest
The full changelog is available at https://docs.pytest.org/en/latest/changelog.html.
Thanks to all who contributed to this release, among them:
* Anthony Sottile
* Anton Lodder
* Bruno Oliveira
* Daniel Hahler
* David Vo
* Oscar Benjamin
* Ronny Pfannschmidt
* Victor Maryama
* Yoav Caspi
* dmitry.dygalo
Happy testing,
The pytest Development Team

View File

@@ -0,0 +1,37 @@
pytest-4.2.0
=======================================
The pytest team is proud to announce the 4.2.0 release!
pytest is a mature Python testing tool with more than a 2000 tests
against itself, passing on many different interpreters and platforms.
This release contains a number of bugs fixes and improvements, so users are encouraged
to take a look at the CHANGELOG:
https://docs.pytest.org/en/latest/changelog.html
For complete documentation, please visit:
https://docs.pytest.org/en/latest/
As usual, you can upgrade from pypi via:
pip install -U pytest
Thanks to all who contributed to this release, among them:
* Adam Uhlir
* Anthony Sottile
* Bruno Oliveira
* Christopher Dignam
* Daniel Hahler
* Joseph Hunkeler
* Kristoffer Nordstroem
* Ronny Pfannschmidt
* Thomas Hisch
* wim glenn
Happy testing,
The Pytest Development Team

View File

@@ -0,0 +1,30 @@
pytest-4.2.1
=======================================
pytest 4.2.1 has just been released to PyPI.
This is a bug-fix release, being a drop-in replacement. To upgrade::
pip install --upgrade pytest
The full changelog is available at https://docs.pytest.org/en/latest/changelog.html.
Thanks to all who contributed to this release, among them:
* Anthony Sottile
* Arel Cordero
* Bruno Oliveira
* Daniel Hahler
* Holger Kohr
* Kevin J. Foley
* Nick Murphy
* Paweł Stradomski
* Raphael Pierzina
* Ronny Pfannschmidt
* Sam Brightman
* Thomas Hisch
* Zac Hatfield-Dodds
Happy testing,
The pytest Development Team

View File

@@ -0,0 +1,36 @@
pytest-4.3.0
=======================================
The pytest team is proud to announce the 4.3.0 release!
pytest is a mature Python testing tool with more than a 2000 tests
against itself, passing on many different interpreters and platforms.
This release contains a number of bugs fixes and improvements, so users are encouraged
to take a look at the CHANGELOG:
https://docs.pytest.org/en/latest/changelog.html
For complete documentation, please visit:
https://docs.pytest.org/en/latest/
As usual, you can upgrade from pypi via:
pip install -U pytest
Thanks to all who contributed to this release, among them:
* Andras Mitzki
* Anthony Sottile
* Bruno Oliveira
* Christian Fetzer
* Daniel Hahler
* Grygorii Iermolenko
* R. Alex Matevish
* Ronny Pfannschmidt
* cclauss
Happy testing,
The Pytest Development Team

View File

@@ -0,0 +1,29 @@
pytest-4.3.1
=======================================
pytest 4.3.1 has just been released to PyPI.
This is a bug-fix release, being a drop-in replacement. To upgrade::
pip install --upgrade pytest
The full changelog is available at https://docs.pytest.org/en/latest/changelog.html.
Thanks to all who contributed to this release, among them:
* Andras Mitzki
* Anthony Sottile
* Bruno Oliveira
* Daniel Hahler
* Danilo Horta
* Grygorii Iermolenko
* Jeff Hale
* Kyle Altendorf
* Stephan Hoyer
* Zac Hatfield-Dodds
* Zac-HD
* songbowen
Happy testing,
The pytest Development Team

View File

@@ -0,0 +1,39 @@
pytest-4.4.0
=======================================
The pytest team is proud to announce the 4.4.0 release!
pytest is a mature Python testing tool with more than a 2000 tests
against itself, passing on many different interpreters and platforms.
This release contains a number of bugs fixes and improvements, so users are encouraged
to take a look at the CHANGELOG:
https://docs.pytest.org/en/latest/changelog.html
For complete documentation, please visit:
https://docs.pytest.org/en/latest/
As usual, you can upgrade from pypi via:
pip install -U pytest
Thanks to all who contributed to this release, among them:
* Anthony Sottile
* ApaDoctor
* Bernhard M. Wiedemann
* Brian Skinn
* Bruno Oliveira
* Daniel Hahler
* Gary Tyler
* Jeong YunWon
* Miro Hrončok
* Takafumi Arakaki
* henrykironde
* smheidrich
Happy testing,
The Pytest Development Team

View File

@@ -0,0 +1,20 @@
pytest-4.4.1
=======================================
pytest 4.4.1 has just been released to PyPI.
This is a bug-fix release, being a drop-in replacement. To upgrade::
pip install --upgrade pytest
The full changelog is available at https://docs.pytest.org/en/latest/changelog.html.
Thanks to all who contributed to this release, among them:
* Anthony Sottile
* Bruno Oliveira
* Daniel Hahler
Happy testing,
The pytest Development Team

View File

@@ -0,0 +1,33 @@
pytest-4.4.2
=======================================
pytest 4.4.2 has just been released to PyPI.
This is a bug-fix release, being a drop-in replacement. To upgrade::
pip install --upgrade pytest
The full changelog is available at https://docs.pytest.org/en/latest/changelog.html.
Thanks to all who contributed to this release, among them:
* Allan Lewis
* Anthony Sottile
* Bruno Oliveira
* DamianSkrzypczak
* Daniel Hahler
* Don Kirkby
* Douglas Thor
* Hugo
* Ilya Konstantinov
* Jon Dufresne
* Matt Cooper
* Nikolay Kondratyev
* Ondřej Súkup
* Peter Schutt
* Romain Chossart
* Sitaktif
Happy testing,
The pytest Development Team

View File

@@ -12,22 +12,28 @@ Asserting with the ``assert`` statement
``pytest`` allows you to use the standard python ``assert`` for verifying
expectations and values in Python tests. For example, you can write the
following::
following:
.. code-block:: python
# content of test_assert1.py
def f():
return 3
def test_function():
assert f() == 4
to assert that your function returns a certain value. If this assertion fails
you will see the return value of the function call::
you will see the return value of the function call:
.. code-block:: pytest
$ pytest test_assert1.py
=========================== test session starts ============================
platform linux -- Python 3.x.y, pytest-3.x.y, py-1.x.y, pluggy-0.x.y
rootdir: $REGENDOC_TMPDIR, inifile:
platform linux -- Python 3.x.y, pytest-4.x.y, py-1.x.y, pluggy-0.x.y
cachedir: $PYTHON_PREFIX/.pytest_cache
rootdir: $REGENDOC_TMPDIR
collected 1 item
test_assert1.py F [100%]
@@ -40,7 +46,7 @@ you will see the return value of the function call::
E assert 3 == 4
E + where 3 = f()
test_assert1.py:5: AssertionError
test_assert1.py:6: AssertionError
========================= 1 failed in 0.12 seconds =========================
``pytest`` has support for showing the values of the most common subexpressions
@@ -49,7 +55,9 @@ operators. (See :ref:`tbreportdemo`). This allows you to use the
idiomatic python constructs without boilerplate code while not losing
introspection information.
However, if you specify a message with the assertion like this::
However, if you specify a message with the assertion like this:
.. code-block:: python
assert a % 2 == 0, "value was odd, should be even"
@@ -64,50 +72,71 @@ Assertions about expected exceptions
------------------------------------------
In order to write assertions about raised exceptions, you can use
``pytest.raises`` as a context manager like this::
``pytest.raises`` as a context manager like this:
.. code-block:: python
import pytest
def test_zero_division():
with pytest.raises(ZeroDivisionError):
1 / 0
and if you need to have access to the actual exception info you may use::
and if you need to have access to the actual exception info you may use:
.. code-block:: python
def test_recursion_depth():
with pytest.raises(RuntimeError) as excinfo:
def f():
f()
f()
assert 'maximum recursion' in str(excinfo.value)
assert "maximum recursion" in str(excinfo.value)
``excinfo`` is a ``ExceptionInfo`` instance, which is a wrapper around
the actual exception raised. The main attributes of interest are
``.type``, ``.value`` and ``.traceback``.
.. versionchanged:: 3.0
You can pass a ``match`` keyword parameter to the context-manager to test
that a regular expression matches on the string representation of an exception
(similar to the ``TestCase.assertRaisesRegexp`` method from ``unittest``):
In the context manager form you may use the keyword argument
``message`` to specify a custom failure message::
.. code-block:: python
>>> with raises(ZeroDivisionError, message="Expecting ZeroDivisionError"):
... pass
... Failed: Expecting ZeroDivisionError
import pytest
If you want to write test code that works on Python 2.4 as well,
you may also use two other ways to test for an expected exception::
def myfunc():
raise ValueError("Exception 123 raised")
def test_match():
with pytest.raises(ValueError, match=r".* 123 .*"):
myfunc()
The regexp parameter of the ``match`` method is matched with the ``re.search``
function, so in the above example ``match='123'`` would have worked as
well.
There's an alternate form of the ``pytest.raises`` function where you pass
a function that will be executed with the given ``*args`` and ``**kwargs`` and
assert that the given exception is raised:
.. code-block:: python
pytest.raises(ExpectedException, func, *args, **kwargs)
pytest.raises(ExpectedException, "func(*args, **kwargs)")
both of which execute the specified function with args and kwargs and
asserts that the given ``ExpectedException`` is raised. The reporter will
provide you with helpful output in case of failures such as *no
The reporter will provide you with helpful output in case of failures such as *no
exception* or *wrong exception*.
Note that it is also possible to specify a "raises" argument to
``pytest.mark.xfail``, which checks that the test is failing in a more
specific way than just having any exception raised::
specific way than just having any exception raised:
.. code-block:: python
@pytest.mark.xfail(raises=IndexError)
def test_f():
@@ -119,30 +148,13 @@ exceptions your own code is deliberately raising, whereas using
like documenting unfixed bugs (where the test describes what "should" happen)
or bugs in dependencies.
Also, the context manager form accepts a ``match`` keyword parameter to test
that a regular expression matches on the string representation of an exception
(like the ``TestCase.assertRaisesRegexp`` method from ``unittest``)::
import pytest
def myfunc():
raise ValueError("Exception 123 raised")
def test_match():
with pytest.raises(ValueError, match=r'.* 123 .*'):
myfunc()
The regexp parameter of the ``match`` method is matched with the ``re.search``
function. So in the above example ``match='123'`` would have worked as
well.
.. _`assertwarns`:
Assertions about expected warnings
-----------------------------------------
.. versionadded:: 2.8
You can check that code raises a particular warning using
:ref:`pytest.warns <warns>`.
@@ -153,24 +165,30 @@ You can check that code raises a particular warning using
Making use of context-sensitive comparisons
-------------------------------------------------
.. versionadded:: 2.0
``pytest`` has rich support for providing context-sensitive information
when it encounters comparisons. For example::
when it encounters comparisons. For example:
.. code-block:: python
# content of test_assert2.py
def test_set_comparison():
set1 = set("1308")
set2 = set("8035")
assert set1 == set2
if you run this module::
if you run this module:
.. code-block:: pytest
$ pytest test_assert2.py
=========================== test session starts ============================
platform linux -- Python 3.x.y, pytest-3.x.y, py-1.x.y, pluggy-0.x.y
rootdir: $REGENDOC_TMPDIR, inifile:
platform linux -- Python 3.x.y, pytest-4.x.y, py-1.x.y, pluggy-0.x.y
cachedir: $PYTHON_PREFIX/.pytest_cache
rootdir: $REGENDOC_TMPDIR
collected 1 item
test_assert2.py F [100%]
@@ -189,7 +207,7 @@ if you run this module::
E '5'
E Use -v to get the full diff
test_assert2.py:5: AssertionError
test_assert2.py:6: AssertionError
========================= 1 failed in 0.12 seconds =========================
Special comparisons are done for a number of cases:
@@ -200,8 +218,8 @@ Special comparisons are done for a number of cases:
See the :ref:`reporting demo <tbreportdemo>` for many more examples.
Defining your own assertion comparison
----------------------------------------------
Defining your own explanation for failed assertions
---------------------------------------------------
It is possible to add your own detailed explanations by implementing
the ``pytest_assertrepr_compare`` hook.
@@ -210,16 +228,21 @@ the ``pytest_assertrepr_compare`` hook.
:noindex:
As an example consider adding the following hook in a :ref:`conftest.py <conftest.py>`
file which provides an alternative explanation for ``Foo`` objects::
file which provides an alternative explanation for ``Foo`` objects:
.. code-block:: python
# content of conftest.py
from test_foocompare import Foo
def pytest_assertrepr_compare(op, left, right):
if isinstance(left, Foo) and isinstance(right, Foo) and op == "==":
return ['Comparing Foo instances:',
' vals: %s != %s' % (left.val, right.val)]
return ["Comparing Foo instances:", " vals: %s != %s" % (left.val, right.val)]
now, given this test module::
now, given this test module:
.. code-block:: python
# content of test_foocompare.py
class Foo(object):
@@ -229,13 +252,16 @@ now, given this test module::
def __eq__(self, other):
return self.val == other.val
def test_compare():
f1 = Foo(1)
f2 = Foo(2)
assert f1 == f2
you can run the test module and get the custom output defined in
the conftest file::
the conftest file:
.. code-block:: pytest
$ pytest -q test_foocompare.py
F [100%]
@@ -249,51 +275,73 @@ the conftest file::
E assert Comparing Foo instances:
E vals: 1 != 2
test_foocompare.py:11: AssertionError
test_foocompare.py:12: AssertionError
1 failed in 0.12 seconds
.. _assert-details:
.. _`assert introspection`:
Advanced assertion introspection
----------------------------------
Assertion introspection details
-------------------------------
.. versionadded:: 2.1
Reporting details about a failing assertion is achieved by rewriting assert
statements before they are run. Rewritten assert statements put introspection
information into the assertion failure message. ``pytest`` only rewrites test
modules directly discovered by its test collection process, so asserts in
supporting modules which are not themselves test modules will not be rewritten.
.. note::
``pytest`` rewrites test modules on import by using an import
hook to write new ``pyc`` files. Most of the time this works transparently.
However, if you are messing with import yourself, the import hook may
interfere.
If this is the case you have two options:
* Disable rewriting for a specific module by adding the string
``PYTEST_DONT_REWRITE`` to its docstring.
* Disable rewriting for all modules by using ``--assert=plain``.
Additionally, rewriting will fail silently if it cannot write new ``.pyc`` files,
i.e. in a read-only filesystem or a zipfile.
modules directly discovered by its test collection process, so **asserts in
supporting modules which are not themselves test modules will not be rewritten**.
You can manually enable assertion rewriting for an imported module by calling
`register_assert_rewrite <https://docs.pytest.org/en/latest/writing_plugins.html#assertion-rewriting>`_
before you import it (a good place to do that is in your root ``conftest.py``).
For further information, Benjamin Peterson wrote up `Behind the scenes of pytest's new assertion rewriting <http://pybites.blogspot.com/2011/07/behind-scenes-of-pytests-new-assertion.html>`_.
.. versionadded:: 2.1
Assertion rewriting caches files on disk
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
``pytest`` will write back the rewritten modules to disk for caching. You can disable
this behavior (for example to avoid leaving stale ``.pyc`` files around in projects that
move files around a lot) by adding this to the top of your ``conftest.py`` file:
.. code-block:: python
import sys
sys.dont_write_bytecode = True
Note that you still get the benefits of assertion introspection, the only change is that
the ``.pyc`` files won't be cached on disk.
Additionally, rewriting will silently skip caching if it cannot write new ``.pyc`` files,
i.e. in a read-only filesystem or a zipfile.
Disabling assert rewriting
~~~~~~~~~~~~~~~~~~~~~~~~~~
``pytest`` rewrites test modules on import by using an import
hook to write new ``pyc`` files. Most of the time this works transparently.
However, if you are working with the import machinery yourself, the import hook may
interfere.
If this is the case you have two options:
* Disable rewriting for a specific module by adding the string
``PYTEST_DONT_REWRITE`` to its docstring.
* Disable rewriting for all modules by using ``--assert=plain``.
Add assert rewriting as an alternate introspection technique.
.. versionchanged:: 2.1
Introduce the ``--assert`` option. Deprecate ``--no-assert`` and
``--nomagic``.
.. versionchanged:: 3.0
Removes the ``--no-assert`` and ``--nomagic`` options.
Removes the ``--assert=reinterp`` option.

View File

@@ -7,14 +7,16 @@ Keeping backwards compatibility has a very high priority in the pytest project.
With the pytest 3.0 release we introduced a clear communication scheme for when we will actually remove the old busted joint and politely ask you to use the new hotness instead, while giving you enough time to adjust your tests or raise concerns if there are valid reasons to keep deprecated functionality around.
To communicate changes we are already issuing deprecation warnings, but they are not displayed by default. In pytest 3.0 we changed the default setting so that pytest deprecation warnings are displayed if not explicitly silenced (with ``--disable-pytest-warnings``).
To communicate changes we issue deprecation warnings using a custom warning hierarchy (see :ref:`internal-warnings`). These warnings may be suppressed using the standard means: ``-W`` command-line flag or ``filterwarnings`` ini options (see :ref:`warnings`), but we suggest to use these sparingly and temporarily, and heed the warnings when possible.
We will only remove deprecated functionality in major releases (e.g. if we deprecate something in 3.0 we will remove it in 4.0), and keep it around for at least two minor releases (e.g. if we deprecate something in 3.9 and 4.0 is the next release, we will not remove it in 4.0 but in 5.0).
We will only start the removal of deprecated functionality in major releases (e.g. if we deprecate something in 3.0 we will start to remove it in 4.0), and keep it around for at least two minor releases (e.g. if we deprecate something in 3.9 and 4.0 is the next release, we start to remove it in 5.0, not in 4.0).
When the deprecation expires (e.g. 4.0 is released), we won't remove the deprecated functionality immediately, but will use the standard warning filters to turn them into **errors** by default. This approach makes it explicit that removal is imminent, and still gives you time to turn the deprecated feature into a warning instead of an error so it can be dealt with in your own time. In the next minor release (e.g. 4.1), the feature will be effectively removed.
Deprecation Roadmap
-------------------
We track deprecation and removal of features using milestones and the `deprecation <https://github.com/pytest-dev/pytest/issues?q=label%3A%22type%3A+deprecation%22>`_ and `removal <https://github.com/pytest-dev/pytest/labels/type%3A%20removal>`_ labels on GitHub.
Features currently deprecated and removed in previous releases can be found in :ref:`deprecations`.
Following our deprecation policy, after starting issuing deprecation warnings we keep features for *at least* two minor versions before considering removal.
We track future deprecation and removal of features using milestones and the `deprecation <https://github.com/pytest-dev/pytest/issues?q=label%3A%22type%3A+deprecation%22>`_ and `removal <https://github.com/pytest-dev/pytest/labels/type%3A%20removal>`_ labels on GitHub.

View File

@@ -8,18 +8,26 @@ When using bash as your shell, ``pytest`` can use argcomplete
(https://argcomplete.readthedocs.io/) for auto-completion.
For this ``argcomplete`` needs to be installed **and** enabled.
Install argcomplete using::
Install argcomplete using:
sudo pip install 'argcomplete>=0.5.7'
.. code-block:: bash
For global activation of all argcomplete enabled python applications run::
sudo pip install 'argcomplete>=0.5.7'
For global activation of all argcomplete enabled python applications run:
.. code-block:: bash
sudo activate-global-python-argcomplete
For permanent (but not global) ``pytest`` activation, use::
For permanent (but not global) ``pytest`` activation, use:
register-python-argcomplete pytest >> ~/.bashrc
.. code-block:: bash
For one-time activation of argcomplete for ``pytest`` only, use::
register-python-argcomplete pytest >> ~/.bashrc
eval "$(register-python-argcomplete pytest)"
For one-time activation of argcomplete for ``pytest`` only, use:
.. code-block:: bash
eval "$(register-python-argcomplete pytest)"

View File

@@ -12,7 +12,9 @@ For information on plugin hooks and objects, see :ref:`plugins`.
For information on the ``pytest.mark`` mechanism, see :ref:`mark`.
For information about fixtures, see :ref:`fixtures`. To see a complete list of available fixtures (add ``-v`` to also see fixtures with leading ``_``), type ::
For information about fixtures, see :ref:`fixtures`. To see a complete list of available fixtures (add ``-v`` to also see fixtures with leading ``_``), type :
.. code-block:: pytest
$ pytest -q --fixtures
cache
@@ -26,25 +28,29 @@ For information about fixtures, see :ref:`fixtures`. To see a complete list of a
Values can be any object handled by the json stdlib module.
capsys
Enable capturing of writes to ``sys.stdout`` and ``sys.stderr`` and make
captured output available via ``capsys.readouterr()`` method calls
which return a ``(out, err)`` namedtuple. ``out`` and ``err`` will be ``text``
objects.
Enable text capturing of writes to ``sys.stdout`` and ``sys.stderr``.
The captured output is made available via ``capsys.readouterr()`` method
calls, which return a ``(out, err)`` namedtuple.
``out`` and ``err`` will be ``text`` objects.
capsysbinary
Enable capturing of writes to ``sys.stdout`` and ``sys.stderr`` and make
captured output available via ``capsys.readouterr()`` method calls
which return a ``(out, err)`` tuple. ``out`` and ``err`` will be ``bytes``
objects.
Enable bytes capturing of writes to ``sys.stdout`` and ``sys.stderr``.
The captured output is made available via ``capsysbinary.readouterr()``
method calls, which return a ``(out, err)`` namedtuple.
``out`` and ``err`` will be ``bytes`` objects.
capfd
Enable capturing of writes to file descriptors ``1`` and ``2`` and make
captured output available via ``capfd.readouterr()`` method calls
which return a ``(out, err)`` tuple. ``out`` and ``err`` will be ``text``
objects.
Enable text capturing of writes to file descriptors ``1`` and ``2``.
The captured output is made available via ``capfd.readouterr()`` method
calls, which return a ``(out, err)`` namedtuple.
``out`` and ``err`` will be ``text`` objects.
capfdbinary
Enable capturing of write to file descriptors 1 and 2 and make
captured output available via ``capfdbinary.readouterr`` method calls
which return a ``(out, err)`` tuple. ``out`` and ``err`` will be
``bytes`` objects.
Enable bytes capturing of writes to file descriptors ``1`` and ``2``.
The captured output is made available via ``capfd.readouterr()`` method
calls, which return a ``(out, err)`` namedtuple.
``out`` and ``err`` will be ``byte`` objects.
doctest_namespace
Fixture that returns a :py:class:`dict` that will be injected into the namespace of doctests.
pytestconfig
@@ -53,7 +59,7 @@ For information about fixtures, see :ref:`fixtures`. To see a complete list of a
Example::
def test_foo(pytestconfig):
if pytestconfig.getoption("verbose"):
if pytestconfig.getoption("verbose") > 0:
...
record_property
Add an extra properties the calling test.
@@ -66,8 +72,6 @@ For information about fixtures, see :ref:`fixtures`. To see a complete list of a
def test_function(record_property):
record_property("example_key", 1)
record_xml_property
(Deprecated) use record_property.
record_xml_attribute
Add extra xml attributes to the tag for the calling test.
The fixture is callable with ``(name, value)``, with value being
@@ -75,7 +79,7 @@ For information about fixtures, see :ref:`fixtures`. To see a complete list of a
caplog
Access and control log capturing.
Captured logs are available through the following methods::
Captured logs are available through the following properties/methods::
* caplog.text -> string containing formatted log output
* caplog.records -> list of logging.LogRecord instances
@@ -104,7 +108,9 @@ For information about fixtures, see :ref:`fixtures`. To see a complete list of a
See http://docs.python.org/library/warnings.html for information
on warning categories.
tmpdir_factory
Return a TempdirFactory instance for the test session.
Return a :class:`_pytest.tmpdir.TempdirFactory` instance for the test session.
tmp_path_factory
Return a :class:`_pytest.tmpdir.TempPathFactory` instance for the test session.
tmpdir
Return a temporary directory path object
which is unique to each test function invocation,
@@ -113,6 +119,16 @@ For information about fixtures, see :ref:`fixtures`. To see a complete list of a
path object.
.. _`py.path.local`: https://py.readthedocs.io/en/latest/path.html
tmp_path
Return a temporary directory path object
which is unique to each test function invocation,
created as a sub directory of the base temporary
directory. The returned object is a :class:`pathlib.Path`
object.
.. note::
in python < 3.6 this is a pathlib2.Path
no tests ran in 0.12 seconds

View File

@@ -5,7 +5,7 @@
Cache: working with cross-testrun state
=======================================
.. versionadded:: 2.8
Usage
---------
@@ -43,7 +43,9 @@ First, let's create 50 test invocation of which only 2 fail::
if i in (17, 25):
pytest.fail("bad luck")
If you run this for the first time you will see two failures::
If you run this for the first time you will see two failures:
.. code-block:: pytest
$ pytest -q
.................F.......F........................ [100%]
@@ -72,13 +74,16 @@ If you run this for the first time you will see two failures::
test_50.py:6: Failed
2 failed, 48 passed in 0.12 seconds
If you then run it with ``--lf``::
If you then run it with ``--lf``:
.. code-block:: pytest
$ pytest --lf
=========================== test session starts ============================
platform linux -- Python 3.x.y, pytest-3.x.y, py-1.x.y, pluggy-0.x.y
rootdir: $REGENDOC_TMPDIR, inifile:
collected 50 items / 48 deselected
platform linux -- Python 3.x.y, pytest-4.x.y, py-1.x.y, pluggy-0.x.y
cachedir: $PYTHON_PREFIX/.pytest_cache
rootdir: $REGENDOC_TMPDIR
collected 50 items / 48 deselected / 2 selected
run-last-failure: rerun previous 2 failures
test_50.py FF [100%]
@@ -113,12 +118,15 @@ not been run ("deselected").
Now, if you run with the ``--ff`` option, all tests will be run but the first
previous failures will be executed first (as can be seen from the series
of ``FF`` and dots)::
of ``FF`` and dots):
.. code-block:: pytest
$ pytest --ff
=========================== test session starts ============================
platform linux -- Python 3.x.y, pytest-3.x.y, py-1.x.y, pluggy-0.x.y
rootdir: $REGENDOC_TMPDIR, inifile:
platform linux -- Python 3.x.y, pytest-4.x.y, py-1.x.y, pluggy-0.x.y
cachedir: $PYTHON_PREFIX/.pytest_cache
rootdir: $REGENDOC_TMPDIR
collected 50 items
run-last-failure: rerun previous 2 failures first
@@ -160,7 +168,9 @@ Behavior when no tests failed in the last run
When no tests failed in the last run, or when no cached ``lastfailed`` data was
found, ``pytest`` can be configured either to run all of the tests or no tests,
using the ``--last-failed-no-failures`` option, which takes one of the following values::
using the ``--last-failed-no-failures`` option, which takes one of the following values:
.. code-block:: bash
pytest --last-failed --last-failed-no-failures all # run all tests (default behavior)
pytest --last-failed --last-failed-no-failures none # run no tests and exit
@@ -179,11 +189,14 @@ across pytest invocations::
import pytest
import time
def expensive_computation():
print("running expensive computation...")
@pytest.fixture
def mydata(request):
val = request.config.cache.get("example/value", None)
if val is None:
time.sleep(9*0.6) # expensive computation :)
expensive_computation()
val = 42
request.config.cache.set("example/value", val)
return val
@@ -191,8 +204,9 @@ across pytest invocations::
def test_function(mydata):
assert mydata == 23
If you run this command once, it will take a while because
of the sleep::
If you run this command for the first time, you can see the print statement:
.. code-block:: pytest
$ pytest -q
F [100%]
@@ -205,11 +219,15 @@ of the sleep::
> assert mydata == 23
E assert 42 == 23
test_caching.py:14: AssertionError
test_caching.py:17: AssertionError
-------------------------- Captured stdout setup ---------------------------
running expensive computation...
1 failed in 0.12 seconds
If you run it a second time the value will be retrieved from
the cache and this will be quick::
the cache and nothing will be printed:
.. code-block:: pytest
$ pytest -q
F [100%]
@@ -222,7 +240,7 @@ the cache and this will be quick::
> assert mydata == 23
E assert 42 == 23
test_caching.py:14: AssertionError
test_caching.py:17: AssertionError
1 failed in 0.12 seconds
See the :ref:`cache-api` for more details.
@@ -232,18 +250,28 @@ Inspecting Cache content
-------------------------------
You can always peek at the content of the cache using the
``--cache-show`` command line option::
``--cache-show`` command line option:
.. code-block:: pytest
$ pytest --cache-show
=========================== test session starts ============================
platform linux -- Python 3.x.y, pytest-3.x.y, py-1.x.y, pluggy-0.x.y
rootdir: $REGENDOC_TMPDIR, inifile:
cachedir: $REGENDOC_TMPDIR/.pytest_cache
platform linux -- Python 3.x.y, pytest-4.x.y, py-1.x.y, pluggy-0.x.y
cachedir: $PYTHON_PREFIX/.pytest_cache
rootdir: $REGENDOC_TMPDIR
cachedir: $PYTHON_PREFIX/.pytest_cache
------------------------------- cache values -------------------------------
cache/lastfailed contains:
{'test_caching.py::test_function': True}
{'test_50.py::test_num[17]': True,
'test_50.py::test_num[25]': True,
'test_assert1.py::test_function': True,
'test_assert2.py::test_set_comparison': True,
'test_caching.py::test_function': True,
'test_foocompare.py::test_compare': True}
cache/nodeids contains:
['test_caching.py::test_function']
cache/stepwise contains:
[]
example/value contains:
42
@@ -253,10 +281,18 @@ Clearing Cache content
-------------------------------
You can instruct pytest to clear all cache files and values
by adding the ``--cache-clear`` option like this::
by adding the ``--cache-clear`` option like this:
.. code-block:: bash
pytest --cache-clear
This is recommended for invocations from Continuous Integration
servers where isolation and correctness is more important
than speed.
Stepwise
--------
As an alternative to ``--lf -x``, especially for cases where you expect a large part of the test suite will fail, ``--sw``, ``--stepwise`` allows you to fix them one at a time. The test suite will run until the first failure and then stop. At the next invocation, tests will continue from the last failing test and then run until the next failing test. You may use the ``--stepwise-skip`` option to ignore one failing test and stop the test execution on the second failing test instead. This is useful if you get stuck on a failing test and just want to ignore it until later.

View File

@@ -35,7 +35,9 @@ There are two ways in which ``pytest`` can perform capturing:
.. _`disable capturing`:
You can influence output capturing mechanisms from the command line::
You can influence output capturing mechanisms from the command line:
.. code-block:: bash
pytest -s # disable all capturing
pytest --capture=sys # replace sys.stdout/stderr with in-mem files
@@ -52,7 +54,7 @@ is that you can use print statements for debugging::
# content of test_module.py
def setup_function(function):
print ("setting up %s" % function)
print("setting up %s" % function)
def test_func1():
assert True
@@ -61,12 +63,15 @@ is that you can use print statements for debugging::
assert False
and running this module will show you precisely the output
of the failing function and hide the other one::
of the failing function and hide the other one:
.. code-block:: pytest
$ pytest
=========================== test session starts ============================
platform linux -- Python 3.x.y, pytest-3.x.y, py-1.x.y, pluggy-0.x.y
rootdir: $REGENDOC_TMPDIR, inifile:
platform linux -- Python 3.x.y, pytest-4.x.y, py-1.x.y, pluggy-0.x.y
cachedir: $PYTHON_PREFIX/.pytest_cache
rootdir: $REGENDOC_TMPDIR
collected 2 items
test_module.py .F [100%]
@@ -116,11 +121,11 @@ same interface but allows to also capture output from
libraries or subprocesses that directly write to operating
system level output streams (FD1 and FD2).
.. versionadded:: 3.3
The return value from ``readouterr`` changed to a ``namedtuple`` with two attributes, ``out`` and ``err``.
.. versionadded:: 3.3
If the code under test writes non-textual data, you can capture this using
the ``capsysbinary`` fixture which instead returns ``bytes`` from
@@ -128,7 +133,7 @@ the ``readouterr`` method. The ``capfsysbinary`` fixture is currently only
available in python 3.
.. versionadded:: 3.3
If the code under test writes non-textual data, you can capture this using
the ``capfdbinary`` fixture which instead returns ``bytes`` from
@@ -136,7 +141,7 @@ the ``readouterr`` method. The ``capfdbinary`` fixture operates on the
filedescriptor level.
.. versionadded:: 3.0
To temporarily disable capture within a test, both ``capsys``
and ``capfd`` have a ``disabled()`` method that can be used

View File

@@ -1,7 +1,4 @@
.. _changelog:
Changelog history
=================================
.. include:: ../../CHANGELOG.rst

View File

@@ -10,17 +10,15 @@
#
# All configuration values have a default; values that are commented out
# serve to show the default.
# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
# built documents.
#
# The full version, including alpha/beta/rc tags.
# The short X.Y version.
import datetime
import os
import sys
import datetime
from _pytest import __version__ as version
@@ -42,11 +40,13 @@ todo_include_todos = 1
# Add any Sphinx extension module names here, as strings. They can be extensions
# coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
extensions = [
"pygments_pytest",
"sphinx.ext.autodoc",
"sphinx.ext.todo",
"sphinx.ext.autosummary",
"sphinx.ext.intersphinx",
"sphinx.ext.todo",
"sphinx.ext.viewcode",
"sphinx_removed_in",
"sphinxcontrib_trio",
]
@@ -65,7 +65,7 @@ master_doc = "contents"
# General information about the project.
project = u"pytest"
year = datetime.datetime.utcnow().year
copyright = u"20152018 , holger krekel and pytest-dev team"
copyright = u"20152019 , holger krekel and pytest-dev team"
# The language for content autogenerated by Sphinx. Refer to documentation
@@ -329,13 +329,13 @@ texinfo_documents = [
# Example configuration for intersphinx: refer to the Python standard library.
intersphinx_mapping = {"python": ("http://docs.python.org/3", None)}
intersphinx_mapping = {"python": ("https://docs.python.org/3", None)}
def setup(app):
# from sphinx.ext.autodoc import cut_lines
# app.connect('autodoc-process-docstring', cut_lines(4, what=['module']))
app.add_description_unit(
app.add_object_type(
"confval",
"confval",
objname="configuration value",

View File

@@ -33,12 +33,15 @@ Full pytest documentation
reference
goodpractices
flaky
pythonpath
customize
example/index
bash-completion
backwards-compatibility
deprecations
py27-py34-deprecation
historical-notes
license
contributing

View File

@@ -5,7 +5,9 @@ Command line options and configuration file settings
-----------------------------------------------------------------
You can get help on command line options and values in INI-style
configurations files by using the general help option::
configurations files by using the general help option:
.. code-block:: bash
pytest -h # prints options _and_ config file settings
@@ -18,7 +20,7 @@ which were registered by installed plugins.
Initialization: determining rootdir and inifile
-----------------------------------------------
.. versionadded:: 2.7
pytest determines a ``rootdir`` for each test run which depends on
the command line arguments (specified test files, paths) and on
@@ -32,7 +34,7 @@ Here's a summary what ``pytest`` uses ``rootdir`` for:
class name, function name and parametrization (if any).
* Is used by plugins as a stable location to store project/test run specific information;
for example, the internal :ref:`cache <cache>` plugin creates a ``.cache`` subdirectory
for example, the internal :ref:`cache <cache>` plugin creates a ``.pytest_cache`` subdirectory
in ``rootdir`` to store its cross-test run state.
Important to emphasize that ``rootdir`` is **NOT** used to modify ``sys.path``/``PYTHONPATH`` or
@@ -88,16 +90,20 @@ The ``config`` object will subsequently carry these attributes:
- ``config.inifile``: the determined ini-file, may be ``None``.
The rootdir is used a reference directory for constructing test
The rootdir is used as a reference directory for constructing test
addresses ("nodeids") and can be used also by plugins for storing
per-testrun information.
Example::
Example:
.. code-block:: bash
pytest path/to/testdir path/other/
will determine the common ancestor as ``path`` and then
check for ini-files as follows::
check for ini-files as follows:
.. code-block:: text
# first look for pytest.ini files
path/pytest.ini
@@ -127,25 +133,33 @@ progress output, you can write it into a configuration file:
.. code-block:: ini
# content of pytest.ini
# (or tox.ini or setup.cfg)
# content of pytest.ini or tox.ini
# setup.cfg files should use [tool:pytest] section instead
[pytest]
addopts = -ra -q
Alternatively, you can set a ``PYTEST_ADDOPTS`` environment variable to add command
line options while the environment is in use::
line options while the environment is in use:
.. code-block:: bash
export PYTEST_ADDOPTS="-v"
Here's how the command-line is built in the presence of ``addopts`` or the environment variable::
Here's how the command-line is built in the presence of ``addopts`` or the environment variable:
.. code-block:: text
<pytest.ini:addopts> $PYTEST_ADDOPTS <extra command-line arguments>
So if the user executes in the command-line::
So if the user executes in the command-line:
.. code-block:: bash
pytest -m slow
The actual command line executed is::
The actual command line executed is:
.. code-block:: bash
pytest -ra -q -v -m slow

535
doc/en/deprecations.rst Normal file
View File

@@ -0,0 +1,535 @@
.. _deprecations:
Deprecations and Removals
=========================
This page lists all pytest features that are currently deprecated or have been removed in past major releases.
The objective is to give users a clear rationale why a certain feature has been removed, and what alternatives
should be used instead.
.. contents::
:depth: 3
:local:
Deprecated Features
-------------------
Below is a complete list of all pytest features which are considered deprecated. Using those features will issue
:class:`_pytest.warning_types.PytestWarning` or subclasses, which can be filtered using
:ref:`standard warning filters <warnings>`.
.. _`raises message deprecated`:
``"message"`` parameter of ``pytest.raises``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.. deprecated:: 4.1
It is a common mistake to think this parameter will match the exception message, while in fact
it only serves to provide a custom message in case the ``pytest.raises`` check fails. To prevent
users from making this mistake, and because it is believed to be little used, pytest is
deprecating it without providing an alternative for the moment.
If you have a valid use case for this parameter, consider that to obtain the same results
you can just call ``pytest.fail`` manually at the end of the ``with`` statement.
For example:
.. code-block:: python
with pytest.raises(TimeoutError, message="Client got unexpected message"):
wait_for(websocket.recv(), 0.5)
Becomes:
.. code-block:: python
with pytest.raises(TimeoutError):
wait_for(websocket.recv(), 0.5)
pytest.fail("Client got unexpected message")
If you still have concerns about this deprecation and future removal, please comment on
`issue #3974 <https://github.com/pytest-dev/pytest/issues/3974>`__.
``pytest.config`` global
~~~~~~~~~~~~~~~~~~~~~~~~
.. deprecated:: 4.1
The ``pytest.config`` global object is deprecated. Instead use
``request.config`` (via the ``request`` fixture) or if you are a plugin author
use the ``pytest_configure(config)`` hook. Note that many hooks can also access
the ``config`` object indirectly, through ``session.config`` or ``item.config`` for example.
.. _raises-warns-exec:
``raises`` / ``warns`` with a string as the second argument
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.. deprecated:: 4.1
Use the context manager form of these instead. When necessary, invoke ``exec``
directly.
Example:
.. code-block:: python
pytest.raises(ZeroDivisionError, "1 / 0")
pytest.raises(SyntaxError, "a $ b")
pytest.warns(DeprecationWarning, "my_function()")
pytest.warns(SyntaxWarning, "assert(1, 2)")
Becomes:
.. code-block:: python
with pytest.raises(ZeroDivisionError):
1 / 0
with pytest.raises(SyntaxError):
exec("a $ b") # exec is required for invalid syntax
with pytest.warns(DeprecationWarning):
my_function()
with pytest.warns(SyntaxWarning):
exec("assert(1, 2)") # exec is used to avoid a top-level warning
Result log (``--result-log``)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The ``--resultlog`` command line option has been deprecated: it is little used
and there are more modern and better alternatives, for example `pytest-tap <https://tappy.readthedocs.io/en/latest/>`_.
This feature will be effectively removed in pytest 4.0 as the team intends to include a better alternative in the core.
If you have any concerns, please don't hesitate to `open an issue <https://github.com/pytest-dev/pytest/issues>`__.
Removed Features
----------------
As stated in our :ref:`backwards-compatibility` policy, deprecated features are removed only in major releases after
an appropriate period of deprecation has passed.
Using ``Class`` in custom Collectors
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.. versionremoved:: 4.0
Using objects named ``"Class"`` as a way to customize the type of nodes that are collected in ``Collector``
subclasses has been deprecated. Users instead should use ``pytest_pycollect_makeitem`` to customize node types during
collection.
This issue should affect only advanced plugins who create new collection types, so if you see this warning
message please contact the authors so they can change the code.
marks in ``pytest.mark.parametrize``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.. versionremoved:: 4.0
Applying marks to values of a ``pytest.mark.parametrize`` call is now deprecated. For example:
.. code-block:: python
@pytest.mark.parametrize(
"a, b",
[
(3, 9),
pytest.mark.xfail(reason="flaky")(6, 36),
(10, 100),
(20, 200),
(40, 400),
(50, 500),
],
)
def test_foo(a, b):
...
This code applies the ``pytest.mark.xfail(reason="flaky")`` mark to the ``(6, 36)`` value of the above parametrization
call.
This was considered hard to read and understand, and also its implementation presented problems to the code preventing
further internal improvements in the marks architecture.
To update the code, use ``pytest.param``:
.. code-block:: python
@pytest.mark.parametrize(
"a, b",
[
(3, 9),
pytest.param(6, 36, marks=pytest.mark.xfail(reason="flaky")),
(10, 100),
(20, 200),
(40, 400),
(50, 500),
],
)
def test_foo(a, b):
...
``pytest_funcarg__`` prefix
~~~~~~~~~~~~~~~~~~~~~~~~~~~
.. versionremoved:: 4.0
In very early pytest versions fixtures could be defined using the ``pytest_funcarg__`` prefix:
.. code-block:: python
def pytest_funcarg__data():
return SomeData()
Switch over to the ``@pytest.fixture`` decorator:
.. code-block:: python
@pytest.fixture
def data():
return SomeData()
[pytest] section in setup.cfg files
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.. versionremoved:: 4.0
``[pytest]`` sections in ``setup.cfg`` files should now be named ``[tool:pytest]``
to avoid conflicts with other distutils commands.
Metafunc.addcall
~~~~~~~~~~~~~~~~
.. versionremoved:: 4.0
:meth:`_pytest.python.Metafunc.addcall` was a precursor to the current parametrized mechanism. Users should use
:meth:`_pytest.python.Metafunc.parametrize` instead.
Example:
.. code-block:: python
def pytest_generate_tests(metafunc):
metafunc.addcall({"i": 1}, id="1")
metafunc.addcall({"i": 2}, id="2")
Becomes:
.. code-block:: python
def pytest_generate_tests(metafunc):
metafunc.parametrize("i", [1, 2], ids=["1", "2"])
``cached_setup``
~~~~~~~~~~~~~~~~
.. versionremoved:: 4.0
``request.cached_setup`` was the precursor of the setup/teardown mechanism available to fixtures.
Example:
.. code-block:: python
@pytest.fixture
def db_session():
return request.cached_setup(
setup=Session.create, teardown=lambda session: session.close(), scope="module"
)
This should be updated to make use of standard fixture mechanisms:
.. code-block:: python
@pytest.fixture(scope="module")
def db_session():
session = Session.create()
yield session
session.close()
You can consult `funcarg comparison section in the docs <https://docs.pytest.org/en/latest/funcarg_compare.html>`_ for
more information.
pytest_plugins in non-top-level conftest files
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.. versionremoved:: 4.0
Defining ``pytest_plugins`` is now deprecated in non-top-level conftest.py
files because they will activate referenced plugins *globally*, which is surprising because for all other pytest
features ``conftest.py`` files are only *active* for tests at or below it.
``Config.warn`` and ``Node.warn``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.. versionremoved:: 4.0
Those methods were part of the internal pytest warnings system, but since ``3.8`` pytest is using the builtin warning
system for its own warnings, so those two functions are now deprecated.
``Config.warn`` should be replaced by calls to the standard ``warnings.warn``, example:
.. code-block:: python
config.warn("C1", "some warning")
Becomes:
.. code-block:: python
warnings.warn(pytest.PytestWarning("some warning"))
``Node.warn`` now supports two signatures:
* ``node.warn(PytestWarning("some message"))``: is now the **recommended** way to call this function.
The warning instance must be a PytestWarning or subclass.
* ``node.warn("CI", "some message")``: this code/message form has been **removed** and should be converted to the warning instance form above.
record_xml_property
~~~~~~~~~~~~~~~~~~~
.. versionremoved:: 4.0
The ``record_xml_property`` fixture is now deprecated in favor of the more generic ``record_property``, which
can be used by other consumers (for example ``pytest-html``) to obtain custom information about the test run.
This is just a matter of renaming the fixture as the API is the same:
.. code-block:: python
def test_foo(record_xml_property):
...
Change to:
.. code-block:: python
def test_foo(record_property):
...
Passing command-line string to ``pytest.main()``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.. versionremoved:: 4.0
Passing a command-line string to ``pytest.main()`` is deprecated:
.. code-block:: python
pytest.main("-v -s")
Pass a list instead:
.. code-block:: python
pytest.main(["-v", "-s"])
By passing a string, users expect that pytest will interpret that command-line using the shell rules they are working
on (for example ``bash`` or ``Powershell``), but this is very hard/impossible to do in a portable way.
Calling fixtures directly
~~~~~~~~~~~~~~~~~~~~~~~~~
.. versionremoved:: 4.0
Calling a fixture function directly, as opposed to request them in a test function, is deprecated.
For example:
.. code-block:: python
@pytest.fixture
def cell():
return ...
@pytest.fixture
def full_cell():
cell = cell()
cell.make_full()
return cell
This is a great source of confusion to new users, which will often call the fixture functions and request them from test functions interchangeably, which breaks the fixture resolution model.
In those cases just request the function directly in the dependent fixture:
.. code-block:: python
@pytest.fixture
def cell():
return ...
@pytest.fixture
def full_cell(cell):
cell.make_full()
return cell
Alternatively if the fixture function is called multiple times inside a test (making it hard to apply the above pattern) or
if you would like to make minimal changes to the code, you can create a fixture which calls the original function together
with the ``name`` parameter:
.. code-block:: python
def cell():
return ...
@pytest.fixture(name="cell")
def cell_fixture():
return cell()
``yield`` tests
~~~~~~~~~~~~~~~
.. versionremoved:: 4.0
pytest supported ``yield``-style tests, where a test function actually ``yield`` functions and values
that are then turned into proper test methods. Example:
.. code-block:: python
def check(x, y):
assert x ** x == y
def test_squared():
yield check, 2, 4
yield check, 3, 9
This would result into two actual test functions being generated.
This form of test function doesn't support fixtures properly, and users should switch to ``pytest.mark.parametrize``:
.. code-block:: python
@pytest.mark.parametrize("x, y", [(2, 4), (3, 9)])
def test_squared(x, y):
assert x ** x == y
Internal classes accessed through ``Node``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.. versionremoved:: 4.0
Access of ``Module``, ``Function``, ``Class``, ``Instance``, ``File`` and ``Item`` through ``Node`` instances now issue
this warning::
usage of Function.Module is deprecated, please use pytest.Module instead
Users should just ``import pytest`` and access those objects using the ``pytest`` module.
This has been documented as deprecated for years, but only now we are actually emitting deprecation warnings.
``Node.get_marker``
~~~~~~~~~~~~~~~~~~~
.. versionremoved:: 4.0
As part of a large :ref:`marker-revamp`, :meth:`_pytest.nodes.Node.get_marker` is deprecated. See
:ref:`the documentation <update marker code>` on tips on how to update your code.
``somefunction.markname``
~~~~~~~~~~~~~~~~~~~~~~~~~
.. versionremoved:: 4.0
As part of a large :ref:`marker-revamp` we already deprecated using ``MarkInfo``
the only correct way to get markers of an element is via ``node.iter_markers(name)``.
``pytest_namespace``
~~~~~~~~~~~~~~~~~~~~
.. versionremoved:: 4.0
This hook is deprecated because it greatly complicates the pytest internals regarding configuration and initialization, making some
bug fixes and refactorings impossible.
Example of usage:
.. code-block:: python
class MySymbol:
...
def pytest_namespace():
return {"my_symbol": MySymbol()}
Plugin authors relying on this hook should instead require that users now import the plugin modules directly (with an appropriate public API).
As a stopgap measure, plugin authors may still inject their names into pytest's namespace, usually during ``pytest_configure``:
.. code-block:: python
import pytest
def pytest_configure():
pytest.my_symbol = MySymbol()
Reinterpretation mode (``--assert=reinterp``)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.. versionremoved:: 3.0
Reinterpretation mode has now been removed and only plain and rewrite
mode are available, consequently the ``--assert=reinterp`` option is
no longer available. This also means files imported from plugins or
``conftest.py`` will not benefit from improved assertions by
default, you should use ``pytest.register_assert_rewrite()`` to
explicitly turn on assertion rewriting for those files.
Removed command-line options
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.. versionremoved:: 3.0
The following deprecated commandline options were removed:
* ``--genscript``: no longer supported;
* ``--no-assert``: use ``--assert=plain`` instead;
* ``--nomagic``: use ``--assert=plain`` instead;
* ``--report``: use ``-r`` instead;
py.test-X* entry points
~~~~~~~~~~~~~~~~~~~~~~~
.. versionremoved:: 3.0
Removed all ``py.test-X*`` entry points. The versioned, suffixed entry points
were never documented and a leftover from a pre-virtualenv era. These entry
points also created broken entry points in wheels, so removing them also
removes a source of confusion for users.

View File

@@ -4,31 +4,69 @@ Doctest integration for modules and test files
By default all files matching the ``test*.txt`` pattern will
be run through the python standard ``doctest`` module. You
can change the pattern by issuing::
can change the pattern by issuing:
.. code-block:: bash
pytest --doctest-glob='*.rst'
on the command line. Since version ``2.9``, ``--doctest-glob``
can be given multiple times in the command-line.
on the command line. ``--doctest-glob`` can be given multiple times in the command-line.
.. versionadded:: 3.1
If you then have a text file like this:
You can specify the encoding that will be used for those doctest files
using the ``doctest_encoding`` ini option:
.. code-block:: text
.. code-block:: ini
# content of test_example.txt
# content of pytest.ini
[pytest]
doctest_encoding = latin1
hello this is a doctest
>>> x = 3
>>> x
3
The default encoding is UTF-8.
then you can just invoke ``pytest`` directly:
You can also trigger running of doctests
from docstrings in all python modules (including regular
python test modules)::
.. code-block:: pytest
pytest --doctest-modules
$ pytest
=========================== test session starts ============================
platform linux -- Python 3.x.y, pytest-4.x.y, py-1.x.y, pluggy-0.x.y
cachedir: $PYTHON_PREFIX/.pytest_cache
rootdir: $REGENDOC_TMPDIR
collected 1 item
test_example.txt . [100%]
========================= 1 passed in 0.12 seconds =========================
By default, pytest will collect ``test*.txt`` files looking for doctest directives, but you
can pass additional globs using the ``--doctest-glob`` option (multi-allowed).
In addition to text files, you can also execute doctests directly from docstrings of your classes
and functions, including from test modules:
.. code-block:: python
# content of mymodule.py
def something():
""" a doctest in a docstring
>>> something()
42
"""
return 42
.. code-block:: bash
$ pytest --doctest-modules
=========================== test session starts ============================
platform linux -- Python 3.x.y, pytest-4.x.y, py-1.x.y, pluggy-0.x.y
cachedir: $PYTHON_PREFIX/.pytest_cache
rootdir: $REGENDOC_TMPDIR
collected 2 items
mymodule.py . [ 50%]
test_example.txt . [100%]
========================= 2 passed in 0.12 seconds =========================
You can make these changes permanent in your project by
putting them into a pytest.ini file like this:
@@ -39,50 +77,37 @@ putting them into a pytest.ini file like this:
[pytest]
addopts = --doctest-modules
If you then have a text file like this::
.. note::
# content of example.rst
The builtin pytest doctest supports only ``doctest`` blocks, but if you are looking
for more advanced checking over *all* your documentation,
including doctests, ``.. codeblock:: python`` Sphinx directive support,
and any other examples your documentation may include, you may wish to
consider `Sybil <https://sybil.readthedocs.io/en/latest/index.html>`__.
It provides pytest integration out of the box.
hello this is a doctest
>>> x = 3
>>> x
3
and another like this::
Encoding
--------
# content of mymodule.py
def something():
""" a doctest in a docstring
>>> something()
42
"""
return 42
The default encoding is **UTF-8**, but you can specify the encoding
that will be used for those doctest files using the
``doctest_encoding`` ini option:
then you can just invoke ``pytest`` without command line options::
.. code-block:: ini
$ pytest
=========================== test session starts ============================
platform linux -- Python 3.x.y, pytest-3.x.y, py-1.x.y, pluggy-0.x.y
rootdir: $REGENDOC_TMPDIR, inifile: pytest.ini
collected 1 item
# content of pytest.ini
[pytest]
doctest_encoding = latin1
mymodule.py . [100%]
Using 'doctest' options
-----------------------
========================= 1 passed in 0.12 seconds =========================
The standard ``doctest`` module provides some `options <https://docs.python.org/3/library/doctest.html#option-flags>`__
to configure the strictness of doctest tests. In pytest, you can enable those flags using the
configuration file.
It is possible to use fixtures using the ``getfixture`` helper::
# content of example.rst
>>> tmp = getfixture('tmpdir')
>>> ...
>>>
Also, :ref:`usefixtures` and :ref:`autouse` fixtures are supported
when executing text doctest files.
The standard ``doctest`` module provides some setting flags to configure the
strictness of doctest tests. In pytest, you can enable those flags using the
configuration file. To make pytest ignore trailing whitespaces and ignore
For example, to make pytest ignore trailing whitespaces and ignore
lengthy exception stack traces you can just write:
.. code-block:: ini
@@ -99,34 +124,67 @@ Python 3 unchanged:
* ``ALLOW_BYTES``: when enabled, the ``b`` prefix is stripped from byte strings
in expected doctest output.
As with any other option flag, these flags can be enabled in ``pytest.ini`` using
the ``doctest_optionflags`` ini option:
Alternatively, options can be enabled by an inline comment in the doc test
itself:
.. code-block:: ini
[pytest]
doctest_optionflags = ALLOW_UNICODE ALLOW_BYTES
Alternatively, it can be enabled by an inline comment in the doc test
itself::
.. code-block:: rst
# content of example.rst
>>> get_unicode_greeting() # doctest: +ALLOW_UNICODE
'Hello'
By default, pytest would report only the first failure for a given doctest. If
you want to continue the test even when you have failures, do::
By default, pytest would report only the first failure for a given doctest. If
you want to continue the test even when you have failures, do:
.. code-block:: bash
pytest --doctest-modules --doctest-continue-on-failure
Output format
-------------
You can change the diff output format on failure for your doctests
by using one of standard doctest modules format in options
(see :data:`python:doctest.REPORT_UDIFF`, :data:`python:doctest.REPORT_CDIFF`,
:data:`python:doctest.REPORT_NDIFF`, :data:`python:doctest.REPORT_ONLY_FIRST_FAILURE`):
.. code-block:: bash
pytest --doctest-modules --doctest-report none
pytest --doctest-modules --doctest-report udiff
pytest --doctest-modules --doctest-report cdiff
pytest --doctest-modules --doctest-report ndiff
pytest --doctest-modules --doctest-report only_first_failure
pytest-specific features
------------------------
Some features are provided to make writing doctests easier or with better integration with
your existing test suite. Keep in mind however that by using those features you will make
your doctests incompatible with the standard ``doctests`` module.
Using fixtures
^^^^^^^^^^^^^^
It is possible to use fixtures using the ``getfixture`` helper:
.. code-block:: text
# content of example.rst
>>> tmp = getfixture('tmpdir')
>>> ...
>>>
Also, :ref:`usefixtures` and :ref:`autouse` fixtures are supported
when executing text doctest files.
.. _`doctest_namespace`:
The 'doctest_namespace' fixture
-------------------------------
.. versionadded:: 3.0
'doctest_namespace' fixture
^^^^^^^^^^^^^^^^^^^^^^^^^^^
The ``doctest_namespace`` fixture can be used to inject items into the
namespace in which your doctests run. It is intended to be used within
@@ -152,19 +210,18 @@ which can then be used in your doctests directly::
"""
pass
Note that like the normal ``conftest.py``, the fixtures are discovered in the directory tree conftest is in.
Meaning that if you put your doctest with your source code, the relevant conftest.py needs to be in the same directory tree.
Fixtures will not be discovered in a sibling directory tree!
Output format
-------------
Skipping tests dynamically
^^^^^^^^^^^^^^^^^^^^^^^^^^
.. versionadded:: 3.0
.. versionadded:: 4.4
You can change the diff output format on failure for your doctests
by using one of standard doctest modules format in options
(see :data:`python:doctest.REPORT_UDIFF`, :data:`python:doctest.REPORT_CDIFF`,
:data:`python:doctest.REPORT_NDIFF`, :data:`python:doctest.REPORT_ONLY_FIRST_FAILURE`)::
You can use ``pytest.skip`` to dynamically skip doctests. For example::
pytest --doctest-modules --doctest-report none
pytest --doctest-modules --doctest-report udiff
pytest --doctest-modules --doctest-report cdiff
pytest --doctest-modules --doctest-report ndiff
pytest --doctest-modules --doctest-report only_first_failure
>>> import sys, pytest
>>> if sys.platform.startswith('win'):
... pytest.skip('this doctest does not work on Windows')
...

View File

@@ -1,6 +1,6 @@
from pytest import raises
import _pytest._code
import py
import pytest
from pytest import raises
def otherfunc(a, b):
@@ -15,15 +15,11 @@ def otherfunc_multi(a, b):
assert a == b
@pytest.mark.parametrize("param1, param2", [(3, 6)])
def test_generative(param1, param2):
assert param1 * 2 < param2
def pytest_generate_tests(metafunc):
if "param1" in metafunc.fixturenames:
metafunc.addcall(funcargs=dict(param1=3, param2=6))
class TestFailing(object):
def test_simple(self):
def f():
@@ -100,6 +96,30 @@ class TestSpecialisedExplanations(object):
text = "head " * 50 + "f" * 70 + "tail " * 20
assert "f" * 70 not in text
def test_eq_dataclass(self):
from dataclasses import dataclass
@dataclass
class Foo(object):
a: int
b: str
left = Foo(1, "b")
right = Foo(1, "c")
assert left == right
def test_eq_attrs(self):
import attr
@attr.s
class Foo(object):
a = attr.ib()
b = attr.ib()
left = Foo(1, "b")
right = Foo(1, "c")
assert left == right
def test_attribute():
class Foo(object):
@@ -143,11 +163,11 @@ def globf(x):
class TestRaises(object):
def test_raises(self):
s = "qwe" # NOQA
raises(TypeError, "int(s)")
s = "qwe"
raises(TypeError, int, s)
def test_raises_doesnt(self):
raises(IOError, "int('3')")
raises(IOError, int, "3")
def test_raise(self):
raise ValueError("demo error")
@@ -177,7 +197,7 @@ def test_dynamic_compile_shows_nicely():
name = "abc-123"
module = imp.new_module(name)
code = _pytest._code.compile(src, name, "exec")
py.builtin.exec_(code, module.__dict__)
exec(code, module.__dict__)
sys.modules[name] = module
module.foo()
@@ -247,7 +267,7 @@ class TestCustomAssertMsg(object):
b = 2
assert (
A.a == b
), "A.a appears not to be b\n" "or does not appear to be b\none of those"
), "A.a appears not to be b\nor does not appear to be b\none of those"
def test_custom_repr(self):
class JSON(object):

View File

@@ -1,6 +1,7 @@
import pytest
import py
import pytest
mydir = py.path.local(__file__).dirpath()
@@ -10,4 +11,4 @@ def pytest_runtest_setup(item):
return
mod = item.getparent(pytest.Module).obj
if hasattr(mod, "hello"):
print("mod.hello %r" % (mod.hello,))
print("mod.hello {!r}".format(mod.hello))

View File

@@ -1,4 +1,3 @@
hello = "world"

View File

@@ -1,4 +1,3 @@
import py
failure_demo = py.path.local(__file__).dirpath("failure_demo.py")
@@ -10,5 +9,5 @@ def test_failure_demo_fails_properly(testdir):
failure_demo.copy(target)
failure_demo.copy(testdir.tmpdir.join(failure_demo.basename))
result = testdir.runpytest(target, syspathinsert=True)
result.stdout.fnmatch_lines(["*42 failed*"])
result.stdout.fnmatch_lines(["*44 failed*"])
assert result.ret != 0

View File

@@ -24,10 +24,10 @@ example: specifying and selecting acceptance tests
pytest.skip("specify -A to run acceptance tests")
self.tmpdir = request.config.mktemp(request.function.__name__, numbered=True)
def run(self, cmd):
def run(self, *cmd):
""" called by test code to execute an acceptance test. """
self.tmpdir.chdir()
return py.process.cmdexec(cmd)
return subprocess.check_output(cmd).decode()
and the actual test function example:
@@ -36,7 +36,7 @@ and the actual test function example:
def test_some_acceptance_aspect(accept):
accept.tmpdir.mkdir("somesub")
result = accept.run("ls -la")
result = accept.run("ls", "-la")
assert "somesub" in result
If you run this test without specifying a command line option

View File

@@ -1,4 +1,3 @@
import pytest

View File

@@ -9,45 +9,59 @@ Here are some example using the :ref:`mark` mechanism.
Marking test functions and selecting them for a run
----------------------------------------------------
You can "mark" a test function with custom metadata like this::
You can "mark" a test function with custom metadata like this:
.. code-block:: python
# content of test_server.py
import pytest
@pytest.mark.webtest
def test_send_http():
pass # perform some webtest test for your app
pass # perform some webtest test for your app
def test_something_quick():
pass
def test_another():
pass
class TestClass(object):
def test_method(self):
pass
.. versionadded:: 2.2
You can then restrict a test run to only run tests marked with ``webtest``::
You can then restrict a test run to only run tests marked with ``webtest``:
.. code-block:: pytest
$ pytest -v -m webtest
=========================== test session starts ============================
platform linux -- Python 3.x.y, pytest-3.x.y, py-1.x.y, pluggy-0.x.y -- $PYTHON_PREFIX/bin/python3.6
cachedir: .pytest_cache
rootdir: $REGENDOC_TMPDIR, inifile:
collecting ... collected 4 items / 3 deselected
platform linux -- Python 3.x.y, pytest-4.x.y, py-1.x.y, pluggy-0.x.y -- $PYTHON_PREFIX/bin/python
cachedir: $PYTHON_PREFIX/.pytest_cache
rootdir: $REGENDOC_TMPDIR
collecting ... collected 4 items / 3 deselected / 1 selected
test_server.py::test_send_http PASSED [100%]
================== 1 passed, 3 deselected in 0.12 seconds ==================
Or the inverse, running all tests except the webtest ones::
Or the inverse, running all tests except the webtest ones:
.. code-block:: pytest
$ pytest -v -m "not webtest"
=========================== test session starts ============================
platform linux -- Python 3.x.y, pytest-3.x.y, py-1.x.y, pluggy-0.x.y -- $PYTHON_PREFIX/bin/python3.6
cachedir: .pytest_cache
rootdir: $REGENDOC_TMPDIR, inifile:
collecting ... collected 4 items / 1 deselected
platform linux -- Python 3.x.y, pytest-4.x.y, py-1.x.y, pluggy-0.x.y -- $PYTHON_PREFIX/bin/python
cachedir: $PYTHON_PREFIX/.pytest_cache
rootdir: $REGENDOC_TMPDIR
collecting ... collected 4 items / 1 deselected / 3 selected
test_server.py::test_something_quick PASSED [ 33%]
test_server.py::test_another PASSED [ 66%]
@@ -60,45 +74,51 @@ Selecting tests based on their node ID
You can provide one or more :ref:`node IDs <node-id>` as positional
arguments to select only specified tests. This makes it easy to select
tests based on their module, class, method, or function name::
tests based on their module, class, method, or function name:
.. code-block:: pytest
$ pytest -v test_server.py::TestClass::test_method
=========================== test session starts ============================
platform linux -- Python 3.x.y, pytest-3.x.y, py-1.x.y, pluggy-0.x.y -- $PYTHON_PREFIX/bin/python3.6
cachedir: .pytest_cache
rootdir: $REGENDOC_TMPDIR, inifile:
platform linux -- Python 3.x.y, pytest-4.x.y, py-1.x.y, pluggy-0.x.y -- $PYTHON_PREFIX/bin/python
cachedir: $PYTHON_PREFIX/.pytest_cache
rootdir: $REGENDOC_TMPDIR
collecting ... collected 1 item
test_server.py::TestClass::test_method PASSED [100%]
========================= 1 passed in 0.12 seconds =========================
You can also select on the class::
You can also select on the class:
.. code-block:: pytest
$ pytest -v test_server.py::TestClass
=========================== test session starts ============================
platform linux -- Python 3.x.y, pytest-3.x.y, py-1.x.y, pluggy-0.x.y -- $PYTHON_PREFIX/bin/python3.6
cachedir: .pytest_cache
rootdir: $REGENDOC_TMPDIR, inifile:
platform linux -- Python 3.x.y, pytest-4.x.y, py-1.x.y, pluggy-0.x.y -- $PYTHON_PREFIX/bin/python
cachedir: $PYTHON_PREFIX/.pytest_cache
rootdir: $REGENDOC_TMPDIR
collecting ... collected 1 item
test_server.py::TestClass::test_method PASSED [100%]
========================= 1 passed in 0.12 seconds =========================
Or select multiple nodes::
Or select multiple nodes:
$ pytest -v test_server.py::TestClass test_server.py::test_send_http
=========================== test session starts ============================
platform linux -- Python 3.x.y, pytest-3.x.y, py-1.x.y, pluggy-0.x.y -- $PYTHON_PREFIX/bin/python3.6
cachedir: .pytest_cache
rootdir: $REGENDOC_TMPDIR, inifile:
collecting ... collected 2 items
.. code-block:: pytest
test_server.py::TestClass::test_method PASSED [ 50%]
test_server.py::test_send_http PASSED [100%]
$ pytest -v test_server.py::TestClass test_server.py::test_send_http
=========================== test session starts ============================
platform linux -- Python 3.x.y, pytest-4.x.y, py-1.x.y, pluggy-0.x.y -- $PYTHON_PREFIX/bin/python
cachedir: $PYTHON_PREFIX/.pytest_cache
rootdir: $REGENDOC_TMPDIR
collecting ... collected 2 items
========================= 2 passed in 0.12 seconds =========================
test_server.py::TestClass::test_method PASSED [ 50%]
test_server.py::test_send_http PASSED [100%]
========================= 2 passed in 0.12 seconds =========================
.. _node-id:
@@ -124,27 +144,31 @@ Using ``-k expr`` to select tests based on their name
You can use the ``-k`` command line option to specify an expression
which implements a substring match on the test names instead of the
exact match on markers that ``-m`` provides. This makes it easy to
select tests based on their names::
select tests based on their names:
.. code-block:: pytest
$ pytest -v -k http # running with the above defined example module
=========================== test session starts ============================
platform linux -- Python 3.x.y, pytest-3.x.y, py-1.x.y, pluggy-0.x.y -- $PYTHON_PREFIX/bin/python3.6
cachedir: .pytest_cache
rootdir: $REGENDOC_TMPDIR, inifile:
collecting ... collected 4 items / 3 deselected
platform linux -- Python 3.x.y, pytest-4.x.y, py-1.x.y, pluggy-0.x.y -- $PYTHON_PREFIX/bin/python
cachedir: $PYTHON_PREFIX/.pytest_cache
rootdir: $REGENDOC_TMPDIR
collecting ... collected 4 items / 3 deselected / 1 selected
test_server.py::test_send_http PASSED [100%]
================== 1 passed, 3 deselected in 0.12 seconds ==================
And you can also run all tests except the ones that match the keyword::
And you can also run all tests except the ones that match the keyword:
.. code-block:: pytest
$ pytest -k "not send_http" -v
=========================== test session starts ============================
platform linux -- Python 3.x.y, pytest-3.x.y, py-1.x.y, pluggy-0.x.y -- $PYTHON_PREFIX/bin/python3.6
cachedir: .pytest_cache
rootdir: $REGENDOC_TMPDIR, inifile:
collecting ... collected 4 items / 1 deselected
platform linux -- Python 3.x.y, pytest-4.x.y, py-1.x.y, pluggy-0.x.y -- $PYTHON_PREFIX/bin/python
cachedir: $PYTHON_PREFIX/.pytest_cache
rootdir: $REGENDOC_TMPDIR
collecting ... collected 4 items / 1 deselected / 3 selected
test_server.py::test_something_quick PASSED [ 33%]
test_server.py::test_another PASSED [ 66%]
@@ -152,14 +176,16 @@ And you can also run all tests except the ones that match the keyword::
================== 3 passed, 1 deselected in 0.12 seconds ==================
Or to select "http" and "quick" tests::
Or to select "http" and "quick" tests:
.. code-block:: pytest
$ pytest -k "http or quick" -v
=========================== test session starts ============================
platform linux -- Python 3.x.y, pytest-3.x.y, py-1.x.y, pluggy-0.x.y -- $PYTHON_PREFIX/bin/python3.6
cachedir: .pytest_cache
rootdir: $REGENDOC_TMPDIR, inifile:
collecting ... collected 4 items / 2 deselected
platform linux -- Python 3.x.y, pytest-4.x.y, py-1.x.y, pluggy-0.x.y -- $PYTHON_PREFIX/bin/python
cachedir: $PYTHON_PREFIX/.pytest_cache
rootdir: $REGENDOC_TMPDIR
collecting ... collected 4 items / 2 deselected / 2 selected
test_server.py::test_send_http PASSED [ 50%]
test_server.py::test_something_quick PASSED [100%]
@@ -184,31 +210,37 @@ Or to select "http" and "quick" tests::
Registering markers
-------------------------------------
.. versionadded:: 2.2
.. ini-syntax for custom markers:
Registering markers for your test suite is simple::
Registering markers for your test suite is simple:
.. code-block:: ini
# content of pytest.ini
[pytest]
markers =
webtest: mark a test as a webtest.
You can ask which markers exist for your test suite - the list includes our just defined ``webtest`` markers::
You can ask which markers exist for your test suite - the list includes our just defined ``webtest`` markers:
.. code-block:: pytest
$ pytest --markers
@pytest.mark.webtest: mark a test as a webtest.
@pytest.mark.filterwarnings(warning): add a warning filter to the given test. see https://docs.pytest.org/en/latest/warnings.html#pytest-mark-filterwarnings
@pytest.mark.skip(reason=None): skip the given test function with an optional reason. Example: skip(reason="no way of currently testing this") skips the test.
@pytest.mark.skipif(condition): skip the given test function if eval(condition) results in a True value. Evaluation happens within the module global context. Example: skipif('sys.platform == "win32"') skips the test if we are on the win32 platform. see http://pytest.org/latest/skipping.html
@pytest.mark.skipif(condition): skip the given test function if eval(condition) results in a True value. Evaluation happens within the module global context. Example: skipif('sys.platform == "win32"') skips the test if we are on the win32 platform. see https://docs.pytest.org/en/latest/skipping.html
@pytest.mark.xfail(condition, reason=None, run=True, raises=None, strict=False): mark the test function as an expected failure if eval(condition) has a True value. Optionally specify a reason for better reporting and run=False if you don't even want to execute the test function. If only specific exception(s) are expected, you can list them in raises, and if the test fails in other ways, it will be reported as a true failure. See http://pytest.org/latest/skipping.html
@pytest.mark.xfail(condition, reason=None, run=True, raises=None, strict=False): mark the test function as an expected failure if eval(condition) has a True value. Optionally specify a reason for better reporting and run=False if you don't even want to execute the test function. If only specific exception(s) are expected, you can list them in raises, and if the test fails in other ways, it will be reported as a true failure. See https://docs.pytest.org/en/latest/skipping.html
@pytest.mark.parametrize(argnames, argvalues): call a test function multiple times passing in different arguments in turn. argvalues generally needs to be a list of values if argnames specifies only one name or a list of tuples of values if argnames specifies multiple names. Example: @parametrize('arg1', [1,2]) would lead to two calls of the decorated test function, one with arg1=1 and another with arg1=2.see http://pytest.org/latest/parametrize.html for more info and examples.
@pytest.mark.parametrize(argnames, argvalues): call a test function multiple times passing in different arguments in turn. argvalues generally needs to be a list of values if argnames specifies only one name or a list of tuples of values if argnames specifies multiple names. Example: @parametrize('arg1', [1,2]) would lead to two calls of the decorated test function, one with arg1=1 and another with arg1=2.see https://docs.pytest.org/en/latest/parametrize.html for more info and examples.
@pytest.mark.usefixtures(fixturename1, fixturename2, ...): mark tests as needing all of the specified fixtures. see http://pytest.org/latest/fixture.html#usefixtures
@pytest.mark.usefixtures(fixturename1, fixturename2, ...): mark tests as needing all of the specified fixtures. see https://docs.pytest.org/en/latest/fixture.html#usefixtures
@pytest.mark.tryfirst: mark a hook implementation function such that the plugin machinery will try to call it first/as early as possible.
@@ -235,14 +267,19 @@ Marking whole classes or modules
----------------------------------------------------
You may use ``pytest.mark`` decorators with classes to apply markers to all of
its test methods::
its test methods:
.. code-block:: python
# content of test_mark_classlevel.py
import pytest
@pytest.mark.webtest
class TestClass(object):
def test_startup(self):
pass
def test_startup_and_more(self):
pass
@@ -250,17 +287,23 @@ This is equivalent to directly applying the decorator to the
two test functions.
To remain backward-compatible with Python 2.4 you can also set a
``pytestmark`` attribute on a TestClass like this::
``pytestmark`` attribute on a TestClass like this:
.. code-block:: python
import pytest
class TestClass(object):
pytestmark = pytest.mark.webtest
or if you need to use multiple markers you can use a list::
or if you need to use multiple markers you can use a list:
.. code-block:: python
import pytest
class TestClass(object):
pytestmark = [pytest.mark.webtest, pytest.mark.slowtest]
@@ -269,8 +312,12 @@ You can also set a module level marker::
import pytest
pytestmark = pytest.mark.webtest
in which case it will be applied to all functions and
methods defined in the module.
or multiple markers::
pytestmark = [pytest.mark.webtest, pytest.mark.slowtest]
in which case markers will be applied (in left-to-right order) to
all functions and methods defined in the module.
.. _`marking individual tests when using parametrize`:
@@ -279,32 +326,24 @@ Marking individual tests when using parametrize
When using parametrize, applying a mark will make it apply
to each individual test. However it is also possible to
apply a marker to an individual test instance::
apply a marker to an individual test instance:
.. code-block:: python
import pytest
@pytest.mark.foo
@pytest.mark.parametrize(("n", "expected"), [
(1, 2),
pytest.mark.bar((1, 3)),
(2, 3),
])
@pytest.mark.parametrize(
("n", "expected"), [(1, 2), pytest.param((1, 3), marks=pytest.mark.bar), (2, 3)]
)
def test_increment(n, expected):
assert n + 1 == expected
assert n + 1 == expected
In this example the mark "foo" will apply to each of the three
tests, whereas the "bar" mark is only applied to the second test.
Skip and xfail marks can also be applied in this way, see :ref:`skip/xfail with parametrize`.
.. note::
If the data you are parametrizing happen to be single callables, you need to be careful
when marking these items. ``pytest.mark.xfail(my_func)`` won't work because it's also the
signature of a function being decorated. To resolve this ambiguity, you need to pass a
reason argument:
``pytest.mark.xfail(func_bar, reason="Issue#7")``.
.. _`adding a custom marker from a plugin`:
Custom marker and command line option to control test runs
@@ -315,74 +354,99 @@ Custom marker and command line option to control test runs
Plugins can provide custom markers and implement specific behaviour
based on it. This is a self-contained example which adds a command
line option and a parametrized test function marker to run tests
specifies via named environments::
specifies via named environments:
.. code-block:: python
# content of conftest.py
import pytest
def pytest_addoption(parser):
parser.addoption("-E", action="store", metavar="NAME",
help="only run tests matching the environment NAME.")
parser.addoption(
"-E",
action="store",
metavar="NAME",
help="only run tests matching the environment NAME.",
)
def pytest_configure(config):
# register an additional marker
config.addinivalue_line("markers",
"env(name): mark test to run only on named environment")
config.addinivalue_line(
"markers", "env(name): mark test to run only on named environment"
)
def pytest_runtest_setup(item):
envnames = [mark.args[0] for mark in item.iter_markers(name='env')]
envnames = [mark.args[0] for mark in item.iter_markers(name="env")]
if envnames:
if item.config.getoption("-E") not in envnames:
pytest.skip("test requires env in %r" % envnames)
A test file using this local plugin::
A test file using this local plugin:
.. code-block:: python
# content of test_someenv.py
import pytest
@pytest.mark.env("stage1")
def test_basic_db_operation():
pass
and an example invocations specifying a different environment than what
the test needs::
the test needs:
.. code-block:: pytest
$ pytest -E stage2
=========================== test session starts ============================
platform linux -- Python 3.x.y, pytest-3.x.y, py-1.x.y, pluggy-0.x.y
rootdir: $REGENDOC_TMPDIR, inifile:
platform linux -- Python 3.x.y, pytest-4.x.y, py-1.x.y, pluggy-0.x.y
cachedir: $PYTHON_PREFIX/.pytest_cache
rootdir: $REGENDOC_TMPDIR
collected 1 item
test_someenv.py s [100%]
======================== 1 skipped in 0.12 seconds =========================
and here is one that specifies exactly the environment needed::
and here is one that specifies exactly the environment needed:
.. code-block:: pytest
$ pytest -E stage1
=========================== test session starts ============================
platform linux -- Python 3.x.y, pytest-3.x.y, py-1.x.y, pluggy-0.x.y
rootdir: $REGENDOC_TMPDIR, inifile:
platform linux -- Python 3.x.y, pytest-4.x.y, py-1.x.y, pluggy-0.x.y
cachedir: $PYTHON_PREFIX/.pytest_cache
rootdir: $REGENDOC_TMPDIR
collected 1 item
test_someenv.py . [100%]
========================= 1 passed in 0.12 seconds =========================
The ``--markers`` option always gives you a list of available markers::
The ``--markers`` option always gives you a list of available markers:
.. code-block:: pytest
$ pytest --markers
@pytest.mark.env(name): mark test to run only on named environment
@pytest.mark.filterwarnings(warning): add a warning filter to the given test. see https://docs.pytest.org/en/latest/warnings.html#pytest-mark-filterwarnings
@pytest.mark.skip(reason=None): skip the given test function with an optional reason. Example: skip(reason="no way of currently testing this") skips the test.
@pytest.mark.skipif(condition): skip the given test function if eval(condition) results in a True value. Evaluation happens within the module global context. Example: skipif('sys.platform == "win32"') skips the test if we are on the win32 platform. see http://pytest.org/latest/skipping.html
@pytest.mark.skipif(condition): skip the given test function if eval(condition) results in a True value. Evaluation happens within the module global context. Example: skipif('sys.platform == "win32"') skips the test if we are on the win32 platform. see https://docs.pytest.org/en/latest/skipping.html
@pytest.mark.xfail(condition, reason=None, run=True, raises=None, strict=False): mark the test function as an expected failure if eval(condition) has a True value. Optionally specify a reason for better reporting and run=False if you don't even want to execute the test function. If only specific exception(s) are expected, you can list them in raises, and if the test fails in other ways, it will be reported as a true failure. See http://pytest.org/latest/skipping.html
@pytest.mark.xfail(condition, reason=None, run=True, raises=None, strict=False): mark the test function as an expected failure if eval(condition) has a True value. Optionally specify a reason for better reporting and run=False if you don't even want to execute the test function. If only specific exception(s) are expected, you can list them in raises, and if the test fails in other ways, it will be reported as a true failure. See https://docs.pytest.org/en/latest/skipping.html
@pytest.mark.parametrize(argnames, argvalues): call a test function multiple times passing in different arguments in turn. argvalues generally needs to be a list of values if argnames specifies only one name or a list of tuples of values if argnames specifies multiple names. Example: @parametrize('arg1', [1,2]) would lead to two calls of the decorated test function, one with arg1=1 and another with arg1=2.see http://pytest.org/latest/parametrize.html for more info and examples.
@pytest.mark.parametrize(argnames, argvalues): call a test function multiple times passing in different arguments in turn. argvalues generally needs to be a list of values if argnames specifies only one name or a list of tuples of values if argnames specifies multiple names. Example: @parametrize('arg1', [1,2]) would lead to two calls of the decorated test function, one with arg1=1 and another with arg1=2.see https://docs.pytest.org/en/latest/parametrize.html for more info and examples.
@pytest.mark.usefixtures(fixturename1, fixturename2, ...): mark tests as needing all of the specified fixtures. see http://pytest.org/latest/fixture.html#usefixtures
@pytest.mark.usefixtures(fixturename1, fixturename2, ...): mark tests as needing all of the specified fixtures. see https://docs.pytest.org/en/latest/fixture.html#usefixtures
@pytest.mark.tryfirst: mark a hook implementation function such that the plugin machinery will try to call it first/as early as possible.
@@ -396,31 +460,40 @@ Passing a callable to custom markers
.. regendoc:wipe
Below is the config file that will be used in the next examples::
Below is the config file that will be used in the next examples:
.. code-block:: python
# content of conftest.py
import sys
def pytest_runtest_setup(item):
for marker in item.iter_markers(name='my_marker'):
for marker in item.iter_markers(name="my_marker"):
print(marker)
sys.stdout.flush()
A custom marker can have its argument set, i.e. ``args`` and ``kwargs`` properties, defined by either invoking it as a callable or using ``pytest.mark.MARKER_NAME.with_args``. These two methods achieve the same effect most of the time.
However, if there is a callable as the single positional argument with no keyword arguments, using the ``pytest.mark.MARKER_NAME(c)`` will not pass ``c`` as a positional argument but decorate ``c`` with the custom marker (see :ref:`MarkDecorator <mark>`). Fortunately, ``pytest.mark.MARKER_NAME.with_args`` comes to the rescue::
However, if there is a callable as the single positional argument with no keyword arguments, using the ``pytest.mark.MARKER_NAME(c)`` will not pass ``c`` as a positional argument but decorate ``c`` with the custom marker (see :ref:`MarkDecorator <mark>`). Fortunately, ``pytest.mark.MARKER_NAME.with_args`` comes to the rescue:
.. code-block:: python
# content of test_custom_marker.py
import pytest
def hello_world(*args, **kwargs):
return 'Hello World'
return "Hello World"
@pytest.mark.my_marker.with_args(hello_world)
def test_with_args():
pass
The output is as follows::
The output is as follows:
.. code-block:: pytest
$ pytest -q -s
Mark(name='my_marker', args=(<function hello_world at 0xdeadbeef>,), kwargs={})
@@ -438,12 +511,16 @@ Reading markers which were set from multiple places
.. regendoc:wipe
If you are heavily using markers in your test suite you may encounter the case where a marker is applied several times to a test function. From plugin
code you can read over all such settings. Example::
code you can read over all such settings. Example:
.. code-block:: python
# content of test_mark_three_times.py
import pytest
pytestmark = pytest.mark.glob("module", x=1)
@pytest.mark.glob("class", x=2)
class TestClass(object):
@pytest.mark.glob("function", x=3)
@@ -451,17 +528,22 @@ code you can read over all such settings. Example::
pass
Here we have the marker "glob" applied three times to the same
test function. From a conftest file we can read it like this::
test function. From a conftest file we can read it like this:
.. code-block:: python
# content of conftest.py
import sys
def pytest_runtest_setup(item):
for mark in item.iter_markers(name='glob'):
print ("glob args=%s kwargs=%s" %(mark.args, mark.kwargs))
for mark in item.iter_markers(name="glob"):
print("glob args=%s kwargs=%s" % (mark.args, mark.kwargs))
sys.stdout.flush()
Let's run this without capturing output and see what we get::
Let's run this without capturing output and see what we get:
.. code-block:: pytest
$ pytest -q -s
glob args=('function',) kwargs={'x': 3}
@@ -479,7 +561,9 @@ Consider you have a test suite which marks tests for particular platforms,
namely ``pytest.mark.darwin``, ``pytest.mark.win32`` etc. and you
also have tests that run on all platforms and have no specific
marker. If you now want to have a way to only run the tests
for your particular platform, you could use the following plugin::
for your particular platform, you could use the following plugin:
.. code-block:: python
# content of conftest.py
#
@@ -488,6 +572,7 @@ for your particular platform, you could use the following plugin::
ALL = set("darwin linux win32".split())
def pytest_runtest_setup(item):
supported_platforms = ALL.intersection(mark.name for mark in item.iter_markers())
plat = sys.platform
@@ -495,48 +580,60 @@ for your particular platform, you could use the following plugin::
pytest.skip("cannot run on platform %s" % (plat))
then tests will be skipped if they were specified for a different platform.
Let's do a little test file to show how this looks like::
Let's do a little test file to show how this looks like:
.. code-block:: python
# content of test_plat.py
import pytest
@pytest.mark.darwin
def test_if_apple_is_evil():
pass
@pytest.mark.linux
def test_if_linux_works():
pass
@pytest.mark.win32
def test_if_win32_crashes():
pass
def test_runs_everywhere():
pass
then you will see two tests skipped and two executed tests as expected::
then you will see two tests skipped and two executed tests as expected:
.. code-block:: pytest
$ pytest -rs # this option reports skip reasons
=========================== test session starts ============================
platform linux -- Python 3.x.y, pytest-3.x.y, py-1.x.y, pluggy-0.x.y
rootdir: $REGENDOC_TMPDIR, inifile:
platform linux -- Python 3.x.y, pytest-4.x.y, py-1.x.y, pluggy-0.x.y
cachedir: $PYTHON_PREFIX/.pytest_cache
rootdir: $REGENDOC_TMPDIR
collected 4 items
test_plat.py s.s. [100%]
========================= short test summary info ==========================
SKIP [2] $REGENDOC_TMPDIR/conftest.py:12: cannot run on platform linux
SKIPPED [2] $REGENDOC_TMPDIR/conftest.py:13: cannot run on platform linux
=================== 2 passed, 2 skipped in 0.12 seconds ====================
Note that if you specify a platform via the marker-command line option like this::
Note that if you specify a platform via the marker-command line option like this:
.. code-block:: pytest
$ pytest -m linux
=========================== test session starts ============================
platform linux -- Python 3.x.y, pytest-3.x.y, py-1.x.y, pluggy-0.x.y
rootdir: $REGENDOC_TMPDIR, inifile:
collected 4 items / 3 deselected
platform linux -- Python 3.x.y, pytest-4.x.y, py-1.x.y, pluggy-0.x.y
cachedir: $PYTHON_PREFIX/.pytest_cache
rootdir: $REGENDOC_TMPDIR
collected 4 items / 3 deselected / 1 selected
test_plat.py . [100%]
@@ -552,28 +649,38 @@ Automatically adding markers based on test names
If you a test suite where test function names indicate a certain
type of test, you can implement a hook that automatically defines
markers so that you can use the ``-m`` option with it. Let's look
at this test module::
at this test module:
.. code-block:: python
# content of test_module.py
def test_interface_simple():
assert 0
def test_interface_complex():
assert 0
def test_event_simple():
assert 0
def test_something_else():
assert 0
We want to dynamically define two markers and can do it in a
``conftest.py`` plugin::
``conftest.py`` plugin:
.. code-block:: python
# content of conftest.py
import pytest
def pytest_collection_modifyitems(items):
for item in items:
if "interface" in item.nodeid:
@@ -581,48 +688,54 @@ We want to dynamically define two markers and can do it in a
elif "event" in item.nodeid:
item.add_marker(pytest.mark.event)
We can now use the ``-m option`` to select one set::
We can now use the ``-m option`` to select one set:
$ pytest -m interface --tb=short
=========================== test session starts ============================
platform linux -- Python 3.x.y, pytest-3.x.y, py-1.x.y, pluggy-0.x.y
rootdir: $REGENDOC_TMPDIR, inifile:
collected 4 items / 2 deselected
.. code-block:: pytest
test_module.py FF [100%]
$ pytest -m interface --tb=short
=========================== test session starts ============================
platform linux -- Python 3.x.y, pytest-4.x.y, py-1.x.y, pluggy-0.x.y
cachedir: $PYTHON_PREFIX/.pytest_cache
rootdir: $REGENDOC_TMPDIR
collected 4 items / 2 deselected / 2 selected
================================= FAILURES =================================
__________________________ test_interface_simple ___________________________
test_module.py:3: in test_interface_simple
assert 0
E assert 0
__________________________ test_interface_complex __________________________
test_module.py:6: in test_interface_complex
assert 0
E assert 0
================== 2 failed, 2 deselected in 0.12 seconds ==================
test_module.py FF [100%]
or to select both "event" and "interface" tests::
================================= FAILURES =================================
__________________________ test_interface_simple ___________________________
test_module.py:4: in test_interface_simple
assert 0
E assert 0
__________________________ test_interface_complex __________________________
test_module.py:8: in test_interface_complex
assert 0
E assert 0
================== 2 failed, 2 deselected in 0.12 seconds ==================
$ pytest -m "interface or event" --tb=short
=========================== test session starts ============================
platform linux -- Python 3.x.y, pytest-3.x.y, py-1.x.y, pluggy-0.x.y
rootdir: $REGENDOC_TMPDIR, inifile:
collected 4 items / 1 deselected
or to select both "event" and "interface" tests:
test_module.py FFF [100%]
.. code-block:: pytest
================================= FAILURES =================================
__________________________ test_interface_simple ___________________________
test_module.py:3: in test_interface_simple
assert 0
E assert 0
__________________________ test_interface_complex __________________________
test_module.py:6: in test_interface_complex
assert 0
E assert 0
____________________________ test_event_simple _____________________________
test_module.py:9: in test_event_simple
assert 0
E assert 0
================== 3 failed, 1 deselected in 0.12 seconds ==================
$ pytest -m "interface or event" --tb=short
=========================== test session starts ============================
platform linux -- Python 3.x.y, pytest-4.x.y, py-1.x.y, pluggy-0.x.y
cachedir: $PYTHON_PREFIX/.pytest_cache
rootdir: $REGENDOC_TMPDIR
collected 4 items / 1 deselected / 3 selected
test_module.py FFF [100%]
================================= FAILURES =================================
__________________________ test_interface_simple ___________________________
test_module.py:4: in test_interface_simple
assert 0
E assert 0
__________________________ test_interface_complex __________________________
test_module.py:8: in test_interface_complex
assert 0
E assert 0
____________________________ test_event_simple _____________________________
test_module.py:12: in test_event_simple
assert 0
E assert 0
================== 3 failed, 1 deselected in 0.12 seconds ==================

View File

@@ -2,9 +2,11 @@
module containing a parametrized tests testing cross-python
serialization via the pickle module.
"""
import py
import distutils.spawn
import subprocess
import textwrap
import pytest
import _pytest._code
pythonlist = ["python2.7", "python3.4", "python3.5"]
@@ -22,44 +24,46 @@ def python2(request, python1):
class Python(object):
def __init__(self, version, picklefile):
self.pythonpath = py.path.local.sysfind(version)
self.pythonpath = distutils.spawn.find_executable(version)
if not self.pythonpath:
pytest.skip("%r not found" % (version,))
pytest.skip("{!r} not found".format(version))
self.picklefile = picklefile
def dumps(self, obj):
dumpfile = self.picklefile.dirpath("dump.py")
dumpfile.write(
_pytest._code.Source(
"""
import pickle
f = open(%r, 'wb')
s = pickle.dump(%r, f, protocol=2)
f.close()
"""
% (str(self.picklefile), obj)
textwrap.dedent(
r"""
import pickle
f = open({!r}, 'wb')
s = pickle.dump({!r}, f, protocol=2)
f.close()
""".format(
str(self.picklefile), obj
)
)
)
py.process.cmdexec("%s %s" % (self.pythonpath, dumpfile))
subprocess.check_call((self.pythonpath, str(dumpfile)))
def load_and_is_true(self, expression):
loadfile = self.picklefile.dirpath("load.py")
loadfile.write(
_pytest._code.Source(
"""
import pickle
f = open(%r, 'rb')
obj = pickle.load(f)
f.close()
res = eval(%r)
if not res:
raise SystemExit(1)
"""
% (str(self.picklefile), expression)
textwrap.dedent(
r"""
import pickle
f = open({!r}, 'rb')
obj = pickle.load(f)
f.close()
res = eval({!r})
if not res:
raise SystemExit(1)
""".format(
str(self.picklefile), expression
)
)
)
print(loadfile)
py.process.cmdexec("%s %s" % (self.pythonpath, loadfile))
subprocess.check_call((self.pythonpath, str(loadfile)))
@pytest.mark.parametrize("obj", [42, {}, {1: 3}])

View File

@@ -23,12 +23,15 @@ You can create a simple example file:
:literal:
and if you installed `PyYAML`_ or a compatible YAML-parser you can
now execute the test specification::
now execute the test specification:
.. code-block:: pytest
nonpython $ pytest test_simple.yml
=========================== test session starts ============================
platform linux -- Python 3.x.y, pytest-3.x.y, py-1.x.y, pluggy-0.x.y
rootdir: $REGENDOC_TMPDIR/nonpython, inifile:
platform linux -- Python 3.x.y, pytest-4.x.y, py-1.x.y, pluggy-0.x.y
cachedir: $PYTHON_PREFIX/.pytest_cache
rootdir: $REGENDOC_TMPDIR/nonpython
collected 2 items
test_simple.yml F. [100%]
@@ -55,13 +58,15 @@ your own domain specific testing language this way.
will be reported as a (red) string.
``reportinfo()`` is used for representing the test location and is also
consulted when reporting in ``verbose`` mode::
consulted when reporting in ``verbose`` mode:
.. code-block:: pytest
nonpython $ pytest -v
=========================== test session starts ============================
platform linux -- Python 3.x.y, pytest-3.x.y, py-1.x.y, pluggy-0.x.y -- $PYTHON_PREFIX/bin/python3.6
cachedir: .pytest_cache
rootdir: $REGENDOC_TMPDIR/nonpython, inifile:
platform linux -- Python 3.x.y, pytest-4.x.y, py-1.x.y, pluggy-0.x.y -- $PYTHON_PREFIX/bin/python
cachedir: $PYTHON_PREFIX/.pytest_cache
rootdir: $REGENDOC_TMPDIR/nonpython
collecting ... collected 2 items
test_simple.yml::hello FAILED [ 50%]
@@ -77,16 +82,19 @@ consulted when reporting in ``verbose`` mode::
.. regendoc:wipe
While developing your custom test collection and execution it's also
interesting to just look at the collection tree::
interesting to just look at the collection tree:
.. code-block:: pytest
nonpython $ pytest --collect-only
=========================== test session starts ============================
platform linux -- Python 3.x.y, pytest-3.x.y, py-1.x.y, pluggy-0.x.y
rootdir: $REGENDOC_TMPDIR/nonpython, inifile:
platform linux -- Python 3.x.y, pytest-4.x.y, py-1.x.y, pluggy-0.x.y
cachedir: $PYTHON_PREFIX/.pytest_cache
rootdir: $REGENDOC_TMPDIR/nonpython
collected 2 items
<Package '$REGENDOC_TMPDIR/nonpython'>
<YamlFile 'test_simple.yml'>
<YamlItem 'hello'>
<YamlItem 'ok'>
<Package $REGENDOC_TMPDIR/nonpython>
<YamlFile test_simple.yml>
<YamlItem hello>
<YamlItem ok>
======================= no tests ran in 0.12 seconds =======================

View File

@@ -1,5 +1,4 @@
# content of conftest.py
import pytest

View File

@@ -42,14 +42,18 @@ Now we add a test configuration like this::
end = 2
metafunc.parametrize("param1", range(end))
This means that we only run 2 tests if we do not pass ``--all``::
This means that we only run 2 tests if we do not pass ``--all``:
.. code-block:: pytest
$ pytest -q test_compute.py
.. [100%]
2 passed in 0.12 seconds
We run only two computations, so we see two dots.
let's run the full monty::
let's run the full monty:
.. code-block:: pytest
$ pytest -q --all
....F [100%]
@@ -134,23 +138,25 @@ used as the test IDs. These are succinct, but can be a pain to maintain.
In ``test_timedistance_v2``, we specified ``ids`` as a function that can generate a
string representation to make part of the test ID. So our ``datetime`` values use the
label generated by ``idfn``, but because we didn't generate a label for ``timedelta``
objects, they are still using the default pytest representation::
objects, they are still using the default pytest representation:
.. code-block:: pytest
$ pytest test_time.py --collect-only
=========================== test session starts ============================
platform linux -- Python 3.x.y, pytest-3.x.y, py-1.x.y, pluggy-0.x.y
rootdir: $REGENDOC_TMPDIR, inifile:
platform linux -- Python 3.x.y, pytest-4.x.y, py-1.x.y, pluggy-0.x.y
cachedir: $PYTHON_PREFIX/.pytest_cache
rootdir: $REGENDOC_TMPDIR
collected 8 items
<Module 'test_time.py'>
<Function 'test_timedistance_v0[a0-b0-expected0]'>
<Function 'test_timedistance_v0[a1-b1-expected1]'>
<Function 'test_timedistance_v1[forward]'>
<Function 'test_timedistance_v1[backward]'>
<Function 'test_timedistance_v2[20011212-20011211-expected0]'>
<Function 'test_timedistance_v2[20011211-20011212-expected1]'>
<Function 'test_timedistance_v3[forward]'>
<Function 'test_timedistance_v3[backward]'>
<Module test_time.py>
<Function test_timedistance_v0[a0-b0-expected0]>
<Function test_timedistance_v0[a1-b1-expected1]>
<Function test_timedistance_v1[forward]>
<Function test_timedistance_v1[backward]>
<Function test_timedistance_v2[20011212-20011211-expected0]>
<Function test_timedistance_v2[20011211-20011212-expected1]>
<Function test_timedistance_v3[forward]>
<Function test_timedistance_v3[backward]>
======================= no tests ran in 0.12 seconds =======================
@@ -191,33 +197,37 @@ only have to work a bit to construct the correct arguments for pytest's
def test_demo2(self, attribute):
assert isinstance(attribute, str)
this is a fully self-contained example which you can run with::
this is a fully self-contained example which you can run with:
.. code-block:: pytest
$ pytest test_scenarios.py
=========================== test session starts ============================
platform linux -- Python 3.x.y, pytest-3.x.y, py-1.x.y, pluggy-0.x.y
rootdir: $REGENDOC_TMPDIR, inifile:
platform linux -- Python 3.x.y, pytest-4.x.y, py-1.x.y, pluggy-0.x.y
cachedir: $PYTHON_PREFIX/.pytest_cache
rootdir: $REGENDOC_TMPDIR
collected 4 items
test_scenarios.py .... [100%]
========================= 4 passed in 0.12 seconds =========================
If you just collect tests you'll also nicely see 'advanced' and 'basic' as variants for the test function::
If you just collect tests you'll also nicely see 'advanced' and 'basic' as variants for the test function:
.. code-block:: pytest
$ pytest --collect-only test_scenarios.py
=========================== test session starts ============================
platform linux -- Python 3.x.y, pytest-3.x.y, py-1.x.y, pluggy-0.x.y
rootdir: $REGENDOC_TMPDIR, inifile:
platform linux -- Python 3.x.y, pytest-4.x.y, py-1.x.y, pluggy-0.x.y
cachedir: $PYTHON_PREFIX/.pytest_cache
rootdir: $REGENDOC_TMPDIR
collected 4 items
<Module 'test_scenarios.py'>
<Class 'TestSampleWithScenarios'>
<Instance '()'>
<Function 'test_demo1[basic]'>
<Function 'test_demo2[basic]'>
<Function 'test_demo1[advanced]'>
<Function 'test_demo2[advanced]'>
<Module test_scenarios.py>
<Class TestSampleWithScenarios>
<Function test_demo1[basic]>
<Function test_demo2[basic]>
<Function test_demo1[advanced]>
<Function test_demo2[advanced]>
======================= no tests ran in 0.12 seconds =======================
@@ -269,20 +279,25 @@ creates a database object for the actual test invocations::
else:
raise ValueError("invalid internal test config")
Let's first see how it looks like at collection time::
Let's first see how it looks like at collection time:
.. code-block:: pytest
$ pytest test_backends.py --collect-only
=========================== test session starts ============================
platform linux -- Python 3.x.y, pytest-3.x.y, py-1.x.y, pluggy-0.x.y
rootdir: $REGENDOC_TMPDIR, inifile:
platform linux -- Python 3.x.y, pytest-4.x.y, py-1.x.y, pluggy-0.x.y
cachedir: $PYTHON_PREFIX/.pytest_cache
rootdir: $REGENDOC_TMPDIR
collected 2 items
<Module 'test_backends.py'>
<Function 'test_db_initialized[d1]'>
<Function 'test_db_initialized[d2]'>
<Module test_backends.py>
<Function test_db_initialized[d1]>
<Function test_db_initialized[d2]>
======================= no tests ran in 0.12 seconds =======================
And then when we run the test::
And then when we run the test:
.. code-block:: pytest
$ pytest -q test_backends.py
.F [100%]
@@ -330,15 +345,18 @@ will be passed to respective fixture function::
assert x == 'aaa'
assert y == 'b'
The result of this test will be successful::
The result of this test will be successful:
.. code-block:: pytest
$ pytest test_indirect_list.py --collect-only
=========================== test session starts ============================
platform linux -- Python 3.x.y, pytest-3.x.y, py-1.x.y, pluggy-0.x.y
rootdir: $REGENDOC_TMPDIR, inifile:
platform linux -- Python 3.x.y, pytest-4.x.y, py-1.x.y, pluggy-0.x.y
cachedir: $PYTHON_PREFIX/.pytest_cache
rootdir: $REGENDOC_TMPDIR
collected 1 item
<Module 'test_indirect_list.py'>
<Function 'test_indirect[a-b]'>
<Module test_indirect_list.py>
<Function test_indirect[a-b]>
======================= no tests ran in 0.12 seconds =======================
@@ -375,10 +393,13 @@ parametrizer`_ but in a lot less code::
assert a == b
def test_zerodivision(self, a, b):
pytest.raises(ZeroDivisionError, "a/b")
with pytest.raises(ZeroDivisionError):
a / b
Our test generator looks up a class-level definition which specifies which
argument sets to use for each test function. Let's run it::
argument sets to use for each test function. Let's run it:
.. code-block:: pytest
$ pytest -q
F.. [100%]
@@ -408,12 +429,14 @@ is to be run with different sets of arguments for its three arguments:
.. literalinclude:: multipython.py
Running it results in some skips if we don't have all the python interpreters installed and otherwise runs all combinations (5 interpreters times 5 interpreters times 3 objects to serialize/deserialize)::
Running it results in some skips if we don't have all the python interpreters installed and otherwise runs all combinations (5 interpreters times 5 interpreters times 3 objects to serialize/deserialize):
.. code-block:: pytest
. $ pytest -rs -q multipython.py
...sss...sssssssss...sss... [100%]
========================= short test summary info ==========================
SKIP [15] $REGENDOC_TMPDIR/CWD/multipython.py:28: 'python3.4' not found
SKIPPED [15] $REGENDOC_TMPDIR/CWD/multipython.py:30: 'python3.4' not found
12 passed, 15 skipped in 0.12 seconds
Indirect parametrization of optional implementations/imports
@@ -457,17 +480,20 @@ And finally a little test module::
assert round(basemod.func1(), 3) == round(optmod.func1(), 3)
If you run this with reporting for skips enabled::
If you run this with reporting for skips enabled:
.. code-block:: pytest
$ pytest -rs test_module.py
=========================== test session starts ============================
platform linux -- Python 3.x.y, pytest-3.x.y, py-1.x.y, pluggy-0.x.y
rootdir: $REGENDOC_TMPDIR, inifile:
platform linux -- Python 3.x.y, pytest-4.x.y, py-1.x.y, pluggy-0.x.y
cachedir: $PYTHON_PREFIX/.pytest_cache
rootdir: $REGENDOC_TMPDIR
collected 2 items
test_module.py .s [100%]
========================= short test summary info ==========================
SKIP [1] $REGENDOC_TMPDIR/conftest.py:11: could not import 'opt2'
SKIPPED [1] $REGENDOC_TMPDIR/conftest.py:11: could not import 'opt2'
=================== 1 passed, 1 skipped in 0.12 seconds ====================
@@ -489,21 +515,25 @@ Set marks or test ID for individual parametrized test
--------------------------------------------------------------------
Use ``pytest.param`` to apply marks or set test ID to individual parametrized test.
For example::
For example:
.. code-block:: python
# content of test_pytest_param_example.py
import pytest
@pytest.mark.parametrize('test_input,expected', [
('3+5', 8),
pytest.param('1+7', 8,
marks=pytest.mark.basic),
pytest.param('2+4', 6,
marks=pytest.mark.basic,
id='basic_2+4'),
pytest.param('6*9', 42,
marks=[pytest.mark.basic, pytest.mark.xfail],
id='basic_6*9'),
])
@pytest.mark.parametrize(
"test_input,expected",
[
("3+5", 8),
pytest.param("1+7", 8, marks=pytest.mark.basic),
pytest.param("2+4", 6, marks=pytest.mark.basic, id="basic_2+4"),
pytest.param(
"6*9", 42, marks=[pytest.mark.basic, pytest.mark.xfail], id="basic_6*9"
),
],
)
def test_eval(test_input, expected):
assert eval(test_input) == expected
@@ -512,21 +542,22 @@ we mark the rest three parametrized tests with the custom marker ``basic``,
and for the fourth test we also use the built-in mark ``xfail`` to indicate this
test is expected to fail. For explicitness, we set test ids for some tests.
Then run ``pytest`` with verbose mode and with only the ``basic`` marker::
Then run ``pytest`` with verbose mode and with only the ``basic`` marker:
pytest -v -m basic
============================================ test session starts =============================================
platform linux -- Python 3.x.y, pytest-3.x.y, py-1.x.y, pluggy-0.x.y
rootdir: $REGENDOC_TMPDIR, inifile:
collected 4 items
.. code-block:: pytest
test_pytest_param_example.py::test_eval[1+7-8] PASSED
test_pytest_param_example.py::test_eval[basic_2+4] PASSED
test_pytest_param_example.py::test_eval[basic_6*9] xfail
========================================== short test summary info ===========================================
XFAIL test_pytest_param_example.py::test_eval[basic_6*9]
$ pytest -v -m basic
=========================== test session starts ============================
platform linux -- Python 3.x.y, pytest-4.x.y, py-1.x.y, pluggy-0.x.y -- $PYTHON_PREFIX/bin/python
cachedir: $PYTHON_PREFIX/.pytest_cache
rootdir: $REGENDOC_TMPDIR
collecting ... collected 17 items / 14 deselected / 3 selected
============================================= 1 tests deselected =============================================
test_pytest_param_example.py::test_eval[1+7-8] PASSED [ 33%]
test_pytest_param_example.py::test_eval[basic_2+4] PASSED [ 66%]
test_pytest_param_example.py::test_eval[basic_6*9] XFAIL [100%]
============ 2 passed, 14 deselected, 1 xfailed in 0.12 seconds ============
As the result:
@@ -536,3 +567,50 @@ As the result:
- The test ``test_eval[1+7-8]`` passed, but the name is autogenerated and confusing.
- The test ``test_eval[basic_2+4]`` passed.
- The test ``test_eval[basic_6*9]`` was expected to fail and did fail.
.. _`parametrizing_conditional_raising`:
Parametrizing conditional raising
--------------------------------------------------------------------
Use :func:`pytest.raises` with the
:ref:`pytest.mark.parametrize ref` decorator to write parametrized tests
in which some tests raise exceptions and others do not.
It is helpful to define a no-op context manager ``does_not_raise`` to serve
as a complement to ``raises``. For example::
from contextlib import contextmanager
import pytest
@contextmanager
def does_not_raise():
yield
@pytest.mark.parametrize('example_input,expectation', [
(3, does_not_raise()),
(2, does_not_raise()),
(1, does_not_raise()),
(0, pytest.raises(ZeroDivisionError)),
])
def test_division(example_input, expectation):
"""Test how much I know division."""
with expectation:
assert (6 / example_input) is not None
In the example above, the first three test cases should run unexceptionally,
while the fourth should raise ``ZeroDivisionError``.
If you're only supporting Python 3.7+, you can simply use ``nullcontext``
to define ``does_not_raise``::
from contextlib import nullcontext as does_not_raise
Or, if you're supporting Python 3.3+ you can use::
from contextlib import ExitStack as does_not_raise
Or, if desired, you can ``pip install contextlib2`` and use::
from contextlib2 import ExitStack as does_not_raise

View File

@@ -1,4 +1,5 @@
import sys
import pytest
py3 = sys.version_info[0] >= 3

View File

@@ -1,6 +1,5 @@
def test_exception_syntax():
try:
0/0
0 / 0
except ZeroDivisionError, e:
pass
assert e

View File

@@ -2,4 +2,4 @@ def test_exception_syntax():
try:
0 / 0
except ZeroDivisionError as e:
pass
assert e

View File

@@ -6,7 +6,9 @@ Ignore paths during test collection
You can easily ignore certain test directories and modules during collection
by passing the ``--ignore=path`` option on the cli. ``pytest`` allows multiple
``--ignore`` options. Example::
``--ignore`` options. Example:
.. code-block:: text
tests/
|-- example
@@ -24,20 +26,25 @@ by passing the ``--ignore=path`` option on the cli. ``pytest`` allows multiple
'-- test_world_03.py
Now if you invoke ``pytest`` with ``--ignore=tests/foobar/test_foobar_03.py --ignore=tests/hello/``,
you will see that ``pytest`` only collects test-modules, which do not match the patterns specified::
you will see that ``pytest`` only collects test-modules, which do not match the patterns specified:
========= test session starts ==========
platform darwin -- Python 2.7.10, pytest-2.8.2, py-1.4.30, pluggy-0.3.1
.. code-block:: pytest
=========================== test session starts ============================
platform linux -- Python 3.x.y, pytest-4.x.y, py-1.x.y, pluggy-0.x.y
rootdir: $REGENDOC_TMPDIR, inifile:
collected 5 items
tests/example/test_example_01.py .
tests/example/test_example_02.py .
tests/example/test_example_03.py .
tests/foobar/test_foobar_01.py .
tests/foobar/test_foobar_02.py .
tests/example/test_example_01.py . [ 20%]
tests/example/test_example_02.py . [ 40%]
tests/example/test_example_03.py . [ 60%]
tests/foobar/test_foobar_01.py . [ 80%]
tests/foobar/test_foobar_02.py . [100%]
======= 5 passed in 0.02 seconds =======
========================= 5 passed in 0.02 seconds =========================
The ``--ignore-glob`` option allows to ignore test file paths based on Unix shell-style wildcards.
If you want to exclude test-modules that end with ``_01.py``, execute ``pytest`` with ``--ignore-glob='*_01.py'``.
Deselect tests during test collection
-------------------------------------
@@ -52,7 +59,9 @@ Keeping duplicate paths specified from command line
----------------------------------------------------
Default behavior of ``pytest`` is to ignore duplicate paths specified from the command line.
Example::
Example:
.. code-block:: pytest
pytest path_a path_a
@@ -63,7 +72,9 @@ Example::
Just collect tests once.
To collect duplicate tests, use the ``--keep-duplicates`` option on the cli.
Example::
Example:
.. code-block:: pytest
pytest --keep-duplicates path_a path_a
@@ -73,7 +84,9 @@ Example::
As the collector just works on directories, if you specify twice a single test file, ``pytest`` will
still collect it twice, no matter if the ``--keep-duplicates`` is not specified.
Example::
Example:
.. code-block:: pytest
pytest test_a.py test_a.py
@@ -85,7 +98,9 @@ Example::
Changing directory recursion
-----------------------------------------------------
You can set the :confval:`norecursedirs` option in an ini-file, for example your ``pytest.ini`` in the project root directory::
You can set the :confval:`norecursedirs` option in an ini-file, for example your ``pytest.ini`` in the project root directory:
.. code-block:: ini
# content of pytest.ini
[pytest]
@@ -100,19 +115,23 @@ Changing naming conventions
You can configure different naming conventions by setting
the :confval:`python_files`, :confval:`python_classes` and
:confval:`python_functions` configuration options. Example::
:confval:`python_functions` configuration options.
Here is an example:
.. code-block:: ini
# content of pytest.ini
# Example 1: have pytest look for "check" instead of "test"
# can also be defined in tox.ini or setup.cfg file, although the section
# name in setup.cfg files should be "tool:pytest"
[pytest]
python_files=check_*.py
python_classes=Check
python_functions=*_check
python_files = check_*.py
python_classes = Check
python_functions = *_check
This would make ``pytest`` look for tests in files that match the ``check_*
.py`` glob-pattern, ``Check`` prefixes in classes, and functions and methods
that match ``*_check``. For example, if we have::
that match ``*_check``. For example, if we have::
# content of check_myapp.py
class CheckMyApp(object):
@@ -121,26 +140,38 @@ that match ``*_check``. For example, if we have::
def complex_check(self):
pass
then the test collection looks like this::
The test collection would look like this:
.. code-block:: pytest
$ pytest --collect-only
=========================== test session starts ============================
platform linux -- Python 3.x.y, pytest-3.x.y, py-1.x.y, pluggy-0.x.y
platform linux -- Python 3.x.y, pytest-4.x.y, py-1.x.y, pluggy-0.x.y
cachedir: $PYTHON_PREFIX/.pytest_cache
rootdir: $REGENDOC_TMPDIR, inifile: pytest.ini
collected 2 items
<Module 'check_myapp.py'>
<Class 'CheckMyApp'>
<Instance '()'>
<Function 'simple_check'>
<Function 'complex_check'>
<Module check_myapp.py>
<Class CheckMyApp>
<Function simple_check>
<Function complex_check>
======================= no tests ran in 0.12 seconds =======================
You can check for multiple glob patterns by adding a space between the patterns:
.. code-block:: ini
# Example 2: have pytest look for files with "test" and "example"
# content of pytest.ini, tox.ini, or setup.cfg file (replace "pytest"
# with "tool:pytest" for setup.cfg)
[pytest]
python_files = test_*.py example_*.py
.. note::
the ``python_functions`` and ``python_classes`` options has no effect
for ``unittest.TestCase`` test discovery because pytest delegates
detection of test case methods to unittest code.
discovery of test case methods to unittest code.
Interpreting cmdline arguments as Python packages
-----------------------------------------------------
@@ -148,13 +179,17 @@ Interpreting cmdline arguments as Python packages
You can use the ``--pyargs`` option to make ``pytest`` try
interpreting arguments as python package names, deriving
their file system path and then running the test. For
example if you have unittest2 installed you can type::
example if you have unittest2 installed you can type:
.. code-block:: bash
pytest --pyargs unittest2.test.test_skipping -q
which would run the respective test module. Like with
other options, through an ini-file and the :confval:`addopts` option you
can make this change more permanently::
can make this change more permanently:
.. code-block:: ini
# content of pytest.ini
[pytest]
@@ -167,19 +202,21 @@ treat it as a filesystem path.
Finding out what is collected
-----------------------------------------------
You can always peek at the collection tree without running tests like this::
You can always peek at the collection tree without running tests like this:
.. code-block:: pytest
. $ pytest --collect-only pythoncollection.py
=========================== test session starts ============================
platform linux -- Python 3.x.y, pytest-3.x.y, py-1.x.y, pluggy-0.x.y
platform linux -- Python 3.x.y, pytest-4.x.y, py-1.x.y, pluggy-0.x.y
cachedir: $PYTHON_PREFIX/.pytest_cache
rootdir: $REGENDOC_TMPDIR, inifile: pytest.ini
collected 3 items
<Module 'CWD/pythoncollection.py'>
<Function 'test_function'>
<Class 'TestClass'>
<Instance '()'>
<Function 'test_method'>
<Function 'test_anothermethod'>
<Module CWD/pythoncollection.py>
<Function test_function>
<Class TestClass>
<Function test_method>
<Function test_anothermethod>
======================= no tests ran in 0.12 seconds =======================
@@ -190,7 +227,9 @@ Customizing test collection
.. regendoc:wipe
You can easily instruct ``pytest`` to discover tests from every Python file::
You can easily instruct ``pytest`` to discover tests from every Python file:
.. code-block:: ini
# content of pytest.ini
[pytest]
@@ -223,7 +262,9 @@ and a ``setup.py`` dummy file like this::
0/0 # will raise exception if imported
If you run with a Python 2 interpreter then you will find the one test and will
leave out the ``setup.py`` file::
leave out the ``setup.py`` file:
.. code-block:: pytest
#$ pytest --collect-only
====== test session starts ======
@@ -236,12 +277,29 @@ leave out the ``setup.py`` file::
====== no tests ran in 0.04 seconds ======
If you run with a Python 3 interpreter both the one test and the ``setup.py``
file will be left out::
file will be left out:
.. code-block:: pytest
$ pytest --collect-only
=========================== test session starts ============================
platform linux -- Python 3.x.y, pytest-3.x.y, py-1.x.y, pluggy-0.x.y
platform linux -- Python 3.x.y, pytest-4.x.y, py-1.x.y, pluggy-0.x.y
cachedir: $PYTHON_PREFIX/.pytest_cache
rootdir: $REGENDOC_TMPDIR, inifile: pytest.ini
collected 0 items
======================= no tests ran in 0.12 seconds =======================
It's also possible to ignore files based on Unix shell-style wildcards by adding
patterns to ``collect_ignore_glob``.
The following example ``conftest.py`` ignores the file ``setup.py`` and in
addition all files that end with ``*_py2.py`` when executed with a Python 3
interpreter::
# content of conftest.py
import sys
collect_ignore = ["setup.py"]
if sys.version_info[0] > 2:
collect_ignore_glob = ["*_py2.py"]

View File

@@ -1,32 +1,32 @@
.. _`tbreportdemo`:
Demo of Python failure reports with pytest
==================================================
==========================================
Here is a nice run of several tens of failures
and how ``pytest`` presents things (unfortunately
not showing the nice colors here in the HTML that you
get on the terminal - we are working on that)::
Here is a nice run of several failures and how ``pytest`` presents things:
.. code-block:: pytest
assertion $ pytest failure_demo.py
=========================== test session starts ============================
platform linux -- Python 3.x.y, pytest-3.x.y, py-1.x.y, pluggy-0.x.y
rootdir: $REGENDOC_TMPDIR/assertion, inifile:
collected 42 items
platform linux -- Python 3.x.y, pytest-4.x.y, py-1.x.y, pluggy-0.x.y
cachedir: $PYTHON_PREFIX/.pytest_cache
rootdir: $REGENDOC_TMPDIR/assertion
collected 44 items
failure_demo.py FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF [100%]
failure_demo.py FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF [100%]
================================= FAILURES =================================
____________________________ test_generative[0] ____________________________
___________________________ test_generative[3-6] ___________________________
param1 = 3, param2 = 6
@pytest.mark.parametrize("param1, param2", [(3, 6)])
def test_generative(param1, param2):
> assert param1 * 2 < param2
E assert (3 * 2) < 6
failure_demo.py:19: AssertionError
failure_demo.py:20: AssertionError
_________________________ TestFailing.test_simple __________________________
self = <failure_demo.TestFailing object at 0xdeadbeef>
@@ -43,7 +43,7 @@ get on the terminal - we are working on that)::
E + where 42 = <function TestFailing.test_simple.<locals>.f at 0xdeadbeef>()
E + and 43 = <function TestFailing.test_simple.<locals>.g at 0xdeadbeef>()
failure_demo.py:35: AssertionError
failure_demo.py:31: AssertionError
____________________ TestFailing.test_simple_multiline _____________________
self = <failure_demo.TestFailing object at 0xdeadbeef>
@@ -51,7 +51,7 @@ get on the terminal - we are working on that)::
def test_simple_multiline(self):
> otherfunc_multi(42, 6 * 9)
failure_demo.py:38:
failure_demo.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
a = 42, b = 54
@@ -73,7 +73,7 @@ get on the terminal - we are working on that)::
E assert not 42
E + where 42 = <function TestFailing.test_not.<locals>.f at 0xdeadbeef>()
failure_demo.py:44: AssertionError
failure_demo.py:40: AssertionError
_________________ TestSpecialisedExplanations.test_eq_text _________________
self = <failure_demo.TestSpecialisedExplanations object at 0xdeadbeef>
@@ -84,7 +84,7 @@ get on the terminal - we are working on that)::
E - spam
E + eggs
failure_demo.py:49: AssertionError
failure_demo.py:45: AssertionError
_____________ TestSpecialisedExplanations.test_eq_similar_text _____________
self = <failure_demo.TestSpecialisedExplanations object at 0xdeadbeef>
@@ -97,7 +97,7 @@ get on the terminal - we are working on that)::
E + foo 2 bar
E ? ^
failure_demo.py:52: AssertionError
failure_demo.py:48: AssertionError
____________ TestSpecialisedExplanations.test_eq_multiline_text ____________
self = <failure_demo.TestSpecialisedExplanations object at 0xdeadbeef>
@@ -110,7 +110,7 @@ get on the terminal - we are working on that)::
E + eggs
E bar
failure_demo.py:55: AssertionError
failure_demo.py:51: AssertionError
______________ TestSpecialisedExplanations.test_eq_long_text _______________
self = <failure_demo.TestSpecialisedExplanations object at 0xdeadbeef>
@@ -127,7 +127,7 @@ get on the terminal - we are working on that)::
E + 1111111111b222222222
E ? ^
failure_demo.py:60: AssertionError
failure_demo.py:56: AssertionError
_________ TestSpecialisedExplanations.test_eq_long_text_multiline __________
self = <failure_demo.TestSpecialisedExplanations object at 0xdeadbeef>
@@ -147,7 +147,7 @@ get on the terminal - we are working on that)::
E
E ...Full output truncated (7 lines hidden), use '-vv' to show
failure_demo.py:65: AssertionError
failure_demo.py:61: AssertionError
_________________ TestSpecialisedExplanations.test_eq_list _________________
self = <failure_demo.TestSpecialisedExplanations object at 0xdeadbeef>
@@ -158,7 +158,7 @@ get on the terminal - we are working on that)::
E At index 2 diff: 2 != 3
E Use -v to get the full diff
failure_demo.py:68: AssertionError
failure_demo.py:64: AssertionError
______________ TestSpecialisedExplanations.test_eq_list_long _______________
self = <failure_demo.TestSpecialisedExplanations object at 0xdeadbeef>
@@ -171,7 +171,7 @@ get on the terminal - we are working on that)::
E At index 100 diff: 1 != 2
E Use -v to get the full diff
failure_demo.py:73: AssertionError
failure_demo.py:69: AssertionError
_________________ TestSpecialisedExplanations.test_eq_dict _________________
self = <failure_demo.TestSpecialisedExplanations object at 0xdeadbeef>
@@ -189,7 +189,7 @@ get on the terminal - we are working on that)::
E
E ...Full output truncated (2 lines hidden), use '-vv' to show
failure_demo.py:76: AssertionError
failure_demo.py:72: AssertionError
_________________ TestSpecialisedExplanations.test_eq_set __________________
self = <failure_demo.TestSpecialisedExplanations object at 0xdeadbeef>
@@ -207,7 +207,7 @@ get on the terminal - we are working on that)::
E
E ...Full output truncated (2 lines hidden), use '-vv' to show
failure_demo.py:79: AssertionError
failure_demo.py:75: AssertionError
_____________ TestSpecialisedExplanations.test_eq_longer_list ______________
self = <failure_demo.TestSpecialisedExplanations object at 0xdeadbeef>
@@ -218,7 +218,7 @@ get on the terminal - we are working on that)::
E Right contains more items, first extra item: 3
E Use -v to get the full diff
failure_demo.py:82: AssertionError
failure_demo.py:78: AssertionError
_________________ TestSpecialisedExplanations.test_in_list _________________
self = <failure_demo.TestSpecialisedExplanations object at 0xdeadbeef>
@@ -227,7 +227,7 @@ get on the terminal - we are working on that)::
> assert 1 in [0, 2, 3, 4, 5]
E assert 1 in [0, 2, 3, 4, 5]
failure_demo.py:85: AssertionError
failure_demo.py:81: AssertionError
__________ TestSpecialisedExplanations.test_not_in_text_multiline __________
self = <failure_demo.TestSpecialisedExplanations object at 0xdeadbeef>
@@ -246,7 +246,7 @@ get on the terminal - we are working on that)::
E
E ...Full output truncated (2 lines hidden), use '-vv' to show
failure_demo.py:89: AssertionError
failure_demo.py:85: AssertionError
___________ TestSpecialisedExplanations.test_not_in_text_single ____________
self = <failure_demo.TestSpecialisedExplanations object at 0xdeadbeef>
@@ -259,7 +259,7 @@ get on the terminal - we are working on that)::
E single foo line
E ? +++
failure_demo.py:93: AssertionError
failure_demo.py:89: AssertionError
_________ TestSpecialisedExplanations.test_not_in_text_single_long _________
self = <failure_demo.TestSpecialisedExplanations object at 0xdeadbeef>
@@ -272,7 +272,7 @@ get on the terminal - we are working on that)::
E head head foo tail tail tail tail tail tail tail tail tail tail tail tail tail tail tail tail tail tail tail tail
E ? +++
failure_demo.py:97: AssertionError
failure_demo.py:93: AssertionError
______ TestSpecialisedExplanations.test_not_in_text_single_long_term _______
self = <failure_demo.TestSpecialisedExplanations object at 0xdeadbeef>
@@ -285,7 +285,49 @@ get on the terminal - we are working on that)::
E head head fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffftail tail tail tail tail tail tail tail tail tail tail tail tail tail tail tail tail tail tail tail
E ? ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
failure_demo.py:101: AssertionError
failure_demo.py:97: AssertionError
______________ TestSpecialisedExplanations.test_eq_dataclass _______________
self = <failure_demo.TestSpecialisedExplanations object at 0xdeadbeef>
def test_eq_dataclass(self):
from dataclasses import dataclass
@dataclass
class Foo(object):
a: int
b: str
left = Foo(1, "b")
right = Foo(1, "c")
> assert left == right
E AssertionError: assert TestSpecialis...oo(a=1, b='b') == TestSpecialise...oo(a=1, b='c')
E Omitting 1 identical items, use -vv to show
E Differing attributes:
E b: 'b' != 'c'
failure_demo.py:109: AssertionError
________________ TestSpecialisedExplanations.test_eq_attrs _________________
self = <failure_demo.TestSpecialisedExplanations object at 0xdeadbeef>
def test_eq_attrs(self):
import attr
@attr.s
class Foo(object):
a = attr.ib()
b = attr.ib()
left = Foo(1, "b")
right = Foo(1, "c")
> assert left == right
E AssertionError: assert Foo(a=1, b='b') == Foo(a=1, b='c')
E Omitting 1 identical items, use -vv to show
E Differing attributes:
E b: 'b' != 'c'
failure_demo.py:121: AssertionError
______________________________ test_attribute ______________________________
def test_attribute():
@@ -297,7 +339,7 @@ get on the terminal - we are working on that)::
E assert 1 == 2
E + where 1 = <failure_demo.test_attribute.<locals>.Foo object at 0xdeadbeef>.b
failure_demo.py:109: AssertionError
failure_demo.py:129: AssertionError
_________________________ test_attribute_instance __________________________
def test_attribute_instance():
@@ -309,7 +351,7 @@ get on the terminal - we are working on that)::
E + where 1 = <failure_demo.test_attribute_instance.<locals>.Foo object at 0xdeadbeef>.b
E + where <failure_demo.test_attribute_instance.<locals>.Foo object at 0xdeadbeef> = <class 'failure_demo.test_attribute_instance.<locals>.Foo'>()
failure_demo.py:116: AssertionError
failure_demo.py:136: AssertionError
__________________________ test_attribute_failure __________________________
def test_attribute_failure():
@@ -322,7 +364,7 @@ get on the terminal - we are working on that)::
i = Foo()
> assert i.b == 2
failure_demo.py:127:
failure_demo.py:147:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <failure_demo.test_attribute_failure.<locals>.Foo object at 0xdeadbeef>
@@ -331,7 +373,7 @@ get on the terminal - we are working on that)::
> raise Exception("Failed to get attrib")
E Exception: Failed to get attrib
failure_demo.py:122: Exception
failure_demo.py:142: Exception
_________________________ test_attribute_multiple __________________________
def test_attribute_multiple():
@@ -348,31 +390,26 @@ get on the terminal - we are working on that)::
E + and 2 = <failure_demo.test_attribute_multiple.<locals>.Bar object at 0xdeadbeef>.b
E + where <failure_demo.test_attribute_multiple.<locals>.Bar object at 0xdeadbeef> = <class 'failure_demo.test_attribute_multiple.<locals>.Bar'>()
failure_demo.py:137: AssertionError
failure_demo.py:157: AssertionError
__________________________ TestRaises.test_raises __________________________
self = <failure_demo.TestRaises object at 0xdeadbeef>
def test_raises(self):
s = "qwe" # NOQA
> raises(TypeError, "int(s)")
s = "qwe"
> raises(TypeError, int, s)
E ValueError: invalid literal for int() with base 10: 'qwe'
failure_demo.py:147:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> int(s)
E ValueError: invalid literal for int() with base 10: 'qwe'
<0-codegen $PYTHON_PREFIX/lib/python3.6/site-packages/_pytest/python_api.py:635>:1: ValueError
failure_demo.py:167: ValueError
______________________ TestRaises.test_raises_doesnt _______________________
self = <failure_demo.TestRaises object at 0xdeadbeef>
def test_raises_doesnt(self):
> raises(IOError, "int('3')")
> raises(IOError, int, "3")
E Failed: DID NOT RAISE <class 'OSError'>
failure_demo.py:150: Failed
failure_demo.py:170: Failed
__________________________ TestRaises.test_raise ___________________________
self = <failure_demo.TestRaises object at 0xdeadbeef>
@@ -381,7 +418,7 @@ get on the terminal - we are working on that)::
> raise ValueError("demo error")
E ValueError: demo error
failure_demo.py:153: ValueError
failure_demo.py:173: ValueError
________________________ TestRaises.test_tupleerror ________________________
self = <failure_demo.TestRaises object at 0xdeadbeef>
@@ -390,7 +427,7 @@ get on the terminal - we are working on that)::
> a, b = [1] # NOQA
E ValueError: not enough values to unpack (expected 2, got 1)
failure_demo.py:156: ValueError
failure_demo.py:176: ValueError
______ TestRaises.test_reinterpret_fails_with_print_for_the_fun_of_it ______
self = <failure_demo.TestRaises object at 0xdeadbeef>
@@ -401,7 +438,7 @@ get on the terminal - we are working on that)::
> a, b = items.pop()
E TypeError: 'int' object is not iterable
failure_demo.py:161: TypeError
failure_demo.py:181: TypeError
--------------------------- Captured stdout call ---------------------------
items is [1, 2, 3]
________________________ TestRaises.test_some_error ________________________
@@ -412,7 +449,7 @@ get on the terminal - we are working on that)::
> if namenotexi: # NOQA
E NameError: name 'namenotexi' is not defined
failure_demo.py:164: NameError
failure_demo.py:184: NameError
____________________ test_dynamic_compile_shows_nicely _____________________
def test_dynamic_compile_shows_nicely():
@@ -423,18 +460,18 @@ get on the terminal - we are working on that)::
name = "abc-123"
module = imp.new_module(name)
code = _pytest._code.compile(src, name, "exec")
py.builtin.exec_(code, module.__dict__)
exec(code, module.__dict__)
sys.modules[name] = module
> module.foo()
failure_demo.py:182:
failure_demo.py:202:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
def foo():
> assert 1 == 0
E AssertionError
<2-codegen 'abc-123' $REGENDOC_TMPDIR/assertion/failure_demo.py:179>:2: AssertionError
<0-codegen 'abc-123' $REGENDOC_TMPDIR/assertion/failure_demo.py:199>:2: AssertionError
____________________ TestMoreErrors.test_complex_error _____________________
self = <failure_demo.TestMoreErrors object at 0xdeadbeef>
@@ -448,7 +485,7 @@ get on the terminal - we are working on that)::
> somefunc(f(), g())
failure_demo.py:193:
failure_demo.py:213:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
failure_demo.py:11: in somefunc
otherfunc(x, y)
@@ -470,7 +507,7 @@ get on the terminal - we are working on that)::
> a, b = items
E ValueError: not enough values to unpack (expected 2, got 0)
failure_demo.py:197: ValueError
failure_demo.py:217: ValueError
____________________ TestMoreErrors.test_z2_type_error _____________________
self = <failure_demo.TestMoreErrors object at 0xdeadbeef>
@@ -480,7 +517,7 @@ get on the terminal - we are working on that)::
> a, b = items
E TypeError: 'int' object is not iterable
failure_demo.py:201: TypeError
failure_demo.py:221: TypeError
______________________ TestMoreErrors.test_startswith ______________________
self = <failure_demo.TestMoreErrors object at 0xdeadbeef>
@@ -493,7 +530,7 @@ get on the terminal - we are working on that)::
E + where False = <built-in method startswith of str object at 0xdeadbeef>('456')
E + where <built-in method startswith of str object at 0xdeadbeef> = '123'.startswith
failure_demo.py:206: AssertionError
failure_demo.py:226: AssertionError
__________________ TestMoreErrors.test_startswith_nested ___________________
self = <failure_demo.TestMoreErrors object at 0xdeadbeef>
@@ -512,7 +549,7 @@ get on the terminal - we are working on that)::
E + where '123' = <function TestMoreErrors.test_startswith_nested.<locals>.f at 0xdeadbeef>()
E + and '456' = <function TestMoreErrors.test_startswith_nested.<locals>.g at 0xdeadbeef>()
failure_demo.py:215: AssertionError
failure_demo.py:235: AssertionError
_____________________ TestMoreErrors.test_global_func ______________________
self = <failure_demo.TestMoreErrors object at 0xdeadbeef>
@@ -523,7 +560,7 @@ get on the terminal - we are working on that)::
E + where False = isinstance(43, float)
E + where 43 = globf(42)
failure_demo.py:218: AssertionError
failure_demo.py:238: AssertionError
_______________________ TestMoreErrors.test_instance _______________________
self = <failure_demo.TestMoreErrors object at 0xdeadbeef>
@@ -534,7 +571,7 @@ get on the terminal - we are working on that)::
E assert 42 != 42
E + where 42 = <failure_demo.TestMoreErrors object at 0xdeadbeef>.x
failure_demo.py:222: AssertionError
failure_demo.py:242: AssertionError
_______________________ TestMoreErrors.test_compare ________________________
self = <failure_demo.TestMoreErrors object at 0xdeadbeef>
@@ -544,7 +581,7 @@ get on the terminal - we are working on that)::
E assert 11 < 5
E + where 11 = globf(10)
failure_demo.py:225: AssertionError
failure_demo.py:245: AssertionError
_____________________ TestMoreErrors.test_try_finally ______________________
self = <failure_demo.TestMoreErrors object at 0xdeadbeef>
@@ -555,7 +592,7 @@ get on the terminal - we are working on that)::
> assert x == 0
E assert 1 == 0
failure_demo.py:230: AssertionError
failure_demo.py:250: AssertionError
___________________ TestCustomAssertMsg.test_single_line ___________________
self = <failure_demo.TestCustomAssertMsg object at 0xdeadbeef>
@@ -570,7 +607,7 @@ get on the terminal - we are working on that)::
E assert 1 == 2
E + where 1 = <class 'failure_demo.TestCustomAssertMsg.test_single_line.<locals>.A'>.a
failure_demo.py:241: AssertionError
failure_demo.py:261: AssertionError
____________________ TestCustomAssertMsg.test_multiline ____________________
self = <failure_demo.TestCustomAssertMsg object at 0xdeadbeef>
@@ -582,14 +619,14 @@ get on the terminal - we are working on that)::
b = 2
> assert (
A.a == b
), "A.a appears not to be b\n" "or does not appear to be b\none of those"
), "A.a appears not to be b\nor does not appear to be b\none of those"
E AssertionError: A.a appears not to be b
E or does not appear to be b
E one of those
E assert 1 == 2
E + where 1 = <class 'failure_demo.TestCustomAssertMsg.test_multiline.<locals>.A'>.a
failure_demo.py:248: AssertionError
failure_demo.py:268: AssertionError
___________________ TestCustomAssertMsg.test_custom_repr ___________________
self = <failure_demo.TestCustomAssertMsg object at 0xdeadbeef>
@@ -611,11 +648,5 @@ get on the terminal - we are working on that)::
E assert 1 == 2
E + where 1 = This is JSON\n{\n 'foo': 'bar'\n}.a
failure_demo.py:261: AssertionError
============================= warnings summary =============================
<undetermined location>
Metafunc.addcall is deprecated and scheduled to be removed in pytest 4.0.
Please use Metafunc.parametrize instead.
-- Docs: http://doc.pytest.org/en/latest/warnings.html
================== 42 failed, 1 warnings in 0.12 seconds ===================
failure_demo.py:281: AssertionError
======================== 44 failed in 0.12 seconds =========================

View File

@@ -43,7 +43,9 @@ provide the ``cmdopt`` through a :ref:`fixture function <fixture function>`:
def cmdopt(request):
return request.config.getoption("--cmdopt")
Let's run this without supplying our new option::
Let's run this without supplying our new option:
.. code-block:: pytest
$ pytest -q test_sample.py
F [100%]
@@ -65,7 +67,9 @@ Let's run this without supplying our new option::
first
1 failed in 0.12 seconds
And now with supplying a command line option::
And now with supplying a command line option:
.. code-block:: pytest
$ pytest -q --cmdopt=type2
F [100%]
@@ -103,7 +107,7 @@ the command line arguments before they get processed:
.. code-block:: python
# content of conftest.py
# setuptools plugin
import sys
@@ -117,12 +121,15 @@ the command line arguments before they get processed:
If you have the `xdist plugin <https://pypi.org/project/pytest-xdist/>`_ installed
you will now always perform test runs using a number
of subprocesses close to your CPU. Running in an empty
directory with the above conftest.py::
directory with the above conftest.py:
.. code-block:: pytest
$ pytest
=========================== test session starts ============================
platform linux -- Python 3.x.y, pytest-3.x.y, py-1.x.y, pluggy-0.x.y
rootdir: $REGENDOC_TMPDIR, inifile:
platform linux -- Python 3.x.y, pytest-4.x.y, py-1.x.y, pluggy-0.x.y
cachedir: $PYTHON_PREFIX/.pytest_cache
rootdir: $REGENDOC_TMPDIR
collected 0 items
======================= no tests ran in 0.12 seconds =======================
@@ -175,26 +182,32 @@ We can now write a test module like this:
def test_func_slow():
pass
and when running it will see a skipped "slow" test::
and when running it will see a skipped "slow" test:
.. code-block:: pytest
$ pytest -rs # "-rs" means report details on the little 's'
=========================== test session starts ============================
platform linux -- Python 3.x.y, pytest-3.x.y, py-1.x.y, pluggy-0.x.y
rootdir: $REGENDOC_TMPDIR, inifile:
platform linux -- Python 3.x.y, pytest-4.x.y, py-1.x.y, pluggy-0.x.y
cachedir: $PYTHON_PREFIX/.pytest_cache
rootdir: $REGENDOC_TMPDIR
collected 2 items
test_module.py .s [100%]
========================= short test summary info ==========================
SKIP [1] test_module.py:8: need --runslow option to run
SKIPPED [1] test_module.py:8: need --runslow option to run
=================== 1 passed, 1 skipped in 0.12 seconds ====================
Or run it including the ``slow`` marked test::
Or run it including the ``slow`` marked test:
.. code-block:: pytest
$ pytest --runslow
=========================== test session starts ============================
platform linux -- Python 3.x.y, pytest-3.x.y, py-1.x.y, pluggy-0.x.y
rootdir: $REGENDOC_TMPDIR, inifile:
platform linux -- Python 3.x.y, pytest-4.x.y, py-1.x.y, pluggy-0.x.y
cachedir: $PYTHON_PREFIX/.pytest_cache
rootdir: $REGENDOC_TMPDIR
collected 2 items
test_module.py .. [100%]
@@ -230,7 +243,9 @@ Example:
The ``__tracebackhide__`` setting influences ``pytest`` showing
of tracebacks: the ``checkconfig`` function will not be shown
unless the ``--full-trace`` command line option is specified.
Let's run our little function::
Let's run our little function:
.. code-block:: pytest
$ pytest -q test_checkconfig.py
F [100%]
@@ -327,13 +342,16 @@ It's easy to present extra information in a ``pytest`` run:
def pytest_report_header(config):
return "project deps: mylib-1.1"
which will add the string to the test header accordingly::
which will add the string to the test header accordingly:
.. code-block:: pytest
$ pytest
=========================== test session starts ============================
platform linux -- Python 3.x.y, pytest-3.x.y, py-1.x.y, pluggy-0.x.y
platform linux -- Python 3.x.y, pytest-4.x.y, py-1.x.y, pluggy-0.x.y
cachedir: $PYTHON_PREFIX/.pytest_cache
project deps: mylib-1.1
rootdir: $REGENDOC_TMPDIR, inifile:
rootdir: $REGENDOC_TMPDIR
collected 0 items
======================= no tests ran in 0.12 seconds =======================
@@ -353,25 +371,30 @@ display more information if applicable:
if config.getoption("verbose") > 0:
return ["info1: did you know that ...", "did you?"]
which will add info only when run with "--v"::
which will add info only when run with "--v":
.. code-block:: pytest
$ pytest -v
=========================== test session starts ============================
platform linux -- Python 3.x.y, pytest-3.x.y, py-1.x.y, pluggy-0.x.y -- $PYTHON_PREFIX/bin/python3.6
cachedir: .pytest_cache
platform linux -- Python 3.x.y, pytest-4.x.y, py-1.x.y, pluggy-0.x.y -- $PYTHON_PREFIX/bin/python
cachedir: $PYTHON_PREFIX/.pytest_cache
info1: did you know that ...
did you?
rootdir: $REGENDOC_TMPDIR, inifile:
rootdir: $REGENDOC_TMPDIR
collecting ... collected 0 items
======================= no tests ran in 0.12 seconds =======================
and nothing when run plainly::
and nothing when run plainly:
.. code-block:: pytest
$ pytest
=========================== test session starts ============================
platform linux -- Python 3.x.y, pytest-3.x.y, py-1.x.y, pluggy-0.x.y
rootdir: $REGENDOC_TMPDIR, inifile:
platform linux -- Python 3.x.y, pytest-4.x.y, py-1.x.y, pluggy-0.x.y
cachedir: $PYTHON_PREFIX/.pytest_cache
rootdir: $REGENDOC_TMPDIR
collected 0 items
======================= no tests ran in 0.12 seconds =======================
@@ -403,12 +426,15 @@ out which tests are the slowest. Let's make an artificial test suite:
def test_funcslow2():
time.sleep(0.3)
Now we can profile which test functions execute the slowest::
Now we can profile which test functions execute the slowest:
.. code-block:: pytest
$ pytest --durations=3
=========================== test session starts ============================
platform linux -- Python 3.x.y, pytest-3.x.y, py-1.x.y, pluggy-0.x.y
rootdir: $REGENDOC_TMPDIR, inifile:
platform linux -- Python 3.x.y, pytest-4.x.y, py-1.x.y, pluggy-0.x.y
cachedir: $PYTHON_PREFIX/.pytest_cache
rootdir: $REGENDOC_TMPDIR
collected 3 items
test_some_are_slow.py ... [100%]
@@ -475,12 +501,15 @@ tests in a class. Here is a test module example:
def test_normal():
pass
If we run this::
If we run this:
.. code-block:: pytest
$ pytest -rx
=========================== test session starts ============================
platform linux -- Python 3.x.y, pytest-3.x.y, py-1.x.y, pluggy-0.x.y
rootdir: $REGENDOC_TMPDIR, inifile:
platform linux -- Python 3.x.y, pytest-4.x.y, py-1.x.y, pluggy-0.x.y
cachedir: $PYTHON_PREFIX/.pytest_cache
rootdir: $REGENDOC_TMPDIR
collected 4 items
test_step.py .Fx. [100%]
@@ -496,7 +525,7 @@ If we run this::
test_step.py:11: AssertionError
========================= short test summary info ==========================
XFAIL test_step.py::TestUserHandling::()::test_deletion
XFAIL test_step.py::TestUserHandling::test_deletion
reason: previous test failed (test_modification)
============== 1 failed, 2 passed, 1 xfailed in 0.12 seconds ===============
@@ -556,12 +585,15 @@ the ``db`` fixture:
def test_root(db): # no db here, will error out
pass
We can run this::
We can run this:
.. code-block:: pytest
$ pytest
=========================== test session starts ============================
platform linux -- Python 3.x.y, pytest-3.x.y, py-1.x.y, pluggy-0.x.y
rootdir: $REGENDOC_TMPDIR, inifile:
platform linux -- Python 3.x.y, pytest-4.x.y, py-1.x.y, pluggy-0.x.y
cachedir: $PYTHON_PREFIX/.pytest_cache
rootdir: $REGENDOC_TMPDIR
collected 7 items
test_step.py .Fx. [ 57%]
@@ -574,7 +606,7 @@ We can run this::
file $REGENDOC_TMPDIR/b/test_error.py, line 1
def test_root(db): # no db here, will error out
E fixture 'db' not found
> available fixtures: cache, capfd, capfdbinary, caplog, capsys, capsysbinary, doctest_namespace, monkeypatch, pytestconfig, record_property, record_xml_attribute, record_xml_property, recwarn, tmpdir, tmpdir_factory
> available fixtures: cache, capfd, capfdbinary, caplog, capsys, capsysbinary, doctest_namespace, monkeypatch, pytestconfig, record_property, record_xml_attribute, recwarn, tmp_path, tmp_path_factory, tmpdir, tmpdir_factory
> use 'pytest --fixtures [testpath]' for help on them.
$REGENDOC_TMPDIR/b/test_error.py:1
@@ -667,12 +699,15 @@ if you then have failing tests:
def test_fail2():
assert 0
and run them::
and run them:
.. code-block:: pytest
$ pytest test_module.py
=========================== test session starts ============================
platform linux -- Python 3.x.y, pytest-3.x.y, py-1.x.y, pluggy-0.x.y
rootdir: $REGENDOC_TMPDIR, inifile:
platform linux -- Python 3.x.y, pytest-4.x.y, py-1.x.y, pluggy-0.x.y
cachedir: $PYTHON_PREFIX/.pytest_cache
rootdir: $REGENDOC_TMPDIR
collected 2 items
test_module.py FF [100%]
@@ -696,7 +731,9 @@ and run them::
test_module.py:6: AssertionError
========================= 2 failed in 0.12 seconds =========================
you will have a "failures" file which contains the failing test ids::
you will have a "failures" file which contains the failing test ids:
.. code-block:: bash
$ cat failures
test_module.py::test_fail1 (PYTEST_TMPDIR/test_fail10)
@@ -766,12 +803,15 @@ if you then have failing tests:
def test_fail2():
assert 0
and run it::
and run it:
.. code-block:: pytest
$ pytest -s test_module.py
=========================== test session starts ============================
platform linux -- Python 3.x.y, pytest-3.x.y, py-1.x.y, pluggy-0.x.y
rootdir: $REGENDOC_TMPDIR, inifile:
platform linux -- Python 3.x.y, pytest-4.x.y, py-1.x.y, pluggy-0.x.y
cachedir: $PYTHON_PREFIX/.pytest_cache
rootdir: $REGENDOC_TMPDIR
collected 3 items
test_module.py Esetting up a test failed! test_module.py::test_setup_fails
@@ -814,7 +854,7 @@ information.
``PYTEST_CURRENT_TEST`` environment variable
--------------------------------------------
.. versionadded:: 3.2
Sometimes a test session might get stuck and there might be no easy way to figure out
which test got stuck, for example if pytest was run in quiet mode (``-q``) or you don't have access to the console
@@ -852,6 +892,8 @@ In that order.
can be changed between releases (even bug fixes) so it shouldn't be relied on for scripting
or automation.
.. _freezing-pytest:
Freezing pytest
---------------
@@ -895,6 +937,8 @@ like ``pytest-timeout`` they must be imported explicitly and passed on to pytest
This allows you to execute tests using the frozen
application with standard ``pytest`` command-line options::
application with standard ``pytest`` command-line options:
.. code-block:: bash
./app_main --pytest --verbose --tb=long --junitxml=results.xml test-suite/

View File

@@ -13,7 +13,7 @@ calls it::
@pytest.fixture(scope="session", autouse=True)
def callattr_ahead_of_alltests(request):
print ("callattr_ahead_of_alltests called")
print("callattr_ahead_of_alltests called")
seen = set([None])
session = request.node
for item in session.items:
@@ -31,20 +31,20 @@ will be called ahead of running any tests::
class TestHello(object):
@classmethod
def callme(cls):
print ("callme called!")
print("callme called!")
def test_method1(self):
print ("test_method1 called")
print("test_method1 called")
def test_method2(self):
print ("test_method1 called")
print("test_method1 called")
class TestOther(object):
@classmethod
def callme(cls):
print ("callme other called")
print("callme other called")
def test_other(self):
print ("test other")
print("test other")
# works with unittest as well ...
import unittest
@@ -52,12 +52,14 @@ will be called ahead of running any tests::
class SomeTest(unittest.TestCase):
@classmethod
def callme(self):
print ("SomeTest callme called")
print("SomeTest callme called")
def test_unit1(self):
print ("test_unit1 method called")
print("test_unit1 method called")
If you run this without output capturing::
If you run this without output capturing:
.. code-block:: pytest
$ pytest -q -s test_module.py
callattr_ahead_of_alltests called

View File

@@ -7,7 +7,7 @@ pytest fixtures: explicit, modular, scalable
.. currentmodule:: _pytest.python
.. versionadded:: 2.0/2.3/2.4
.. _`xUnit`: http://en.wikipedia.org/wiki/XUnit
.. _`purpose of test fixtures`: http://en.wikipedia.org/wiki/Test_fixture#Software
@@ -66,12 +66,15 @@ using it::
Here, the ``test_ehlo`` needs the ``smtp_connection`` fixture value. pytest
will discover and call the :py:func:`@pytest.fixture <_pytest.python.fixture>`
marked ``smtp_connection`` fixture function. Running the test looks like this::
marked ``smtp_connection`` fixture function. Running the test looks like this:
.. code-block:: pytest
$ pytest test_smtpsimple.py
=========================== test session starts ============================
platform linux -- Python 3.x.y, pytest-3.x.y, py-1.x.y, pluggy-0.x.y
rootdir: $REGENDOC_TMPDIR, inifile:
platform linux -- Python 3.x.y, pytest-4.x.y, py-1.x.y, pluggy-0.x.y
cachedir: $PYTHON_PREFIX/.pytest_cache
rootdir: $REGENDOC_TMPDIR
collected 1 item
test_smtpsimple.py F [100%]
@@ -111,7 +114,9 @@ with a list of available function arguments.
.. note::
You can always issue ::
You can always issue:
.. code-block:: bash
pytest --fixtures test_simplefactory.py
@@ -153,7 +158,7 @@ This makes use of the automatic caching mechanisms of pytest.
Another good approach is by adding the data files in the ``tests`` folder.
There are also community plugins available to help managing this aspect of
testing, e.g. `pytest-datadir <https://github.com/gabrielcnr/pytest-datadir>`__
testing, e.g. `pytest-datadir <https://pypi.org/project/pytest-datadir/>`__
and `pytest-datafiles <https://pypi.org/project/pytest-datafiles/>`__.
.. _smtpshared:
@@ -171,6 +176,7 @@ to cause the decorated ``smtp_connection`` fixture function to only be invoked
once per test *module* (the default is to invoke once per test *function*).
Multiple test functions in a test module will thus
each receive the same ``smtp_connection`` fixture instance, thus saving time.
Possible values for ``scope`` are: ``function``, ``class``, ``module``, ``package`` or ``session``.
The next example puts the fixture function into a separate ``conftest.py`` file
so that tests from multiple test modules in the directory can
@@ -203,12 +209,15 @@ located)::
assert 0 # for demo purposes
We deliberately insert failing ``assert 0`` statements in order to
inspect what is going on and can now run the tests::
inspect what is going on and can now run the tests:
.. code-block:: pytest
$ pytest test_module.py
=========================== test session starts ============================
platform linux -- Python 3.x.y, pytest-3.x.y, py-1.x.y, pluggy-0.x.y
rootdir: $REGENDOC_TMPDIR, inifile:
platform linux -- Python 3.x.y, pytest-4.x.y, py-1.x.y, pluggy-0.x.y
cachedir: $PYTHON_PREFIX/.pytest_cache
rootdir: $REGENDOC_TMPDIR
collected 2 items
test_module.py FF [100%]
@@ -258,11 +267,16 @@ instance, you can simply declare it:
Finally, the ``class`` scope will invoke the fixture once per test *class*.
.. note::
Pytest will only cache one instance of a fixture at a time.
This means that when using a parametrized fixture, pytest may invoke a fixture more than once in the given scope.
``package`` scope (experimental)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.. versionadded:: 3.7
In pytest 3.7 the ``package`` scope has been introduced. Package-scoped fixtures
are finalized when the last test of a *package* finishes.
@@ -278,7 +292,7 @@ are finalized when the last test of a *package* finishes.
Higher-scoped fixtures are instantiated first
---------------------------------------------
.. versionadded:: 3.5
Within a function request for features, fixture of higher-scopes (such as ``session``) are instantiated first than
lower-scoped fixtures (such as ``function`` or ``class``). The relative order of fixtures of same scope follows
@@ -350,7 +364,9 @@ The ``print`` and ``smtp.close()`` statements will execute when the last test in
the module has finished execution, regardless of the exception status of the
tests.
Let's execute it::
Let's execute it:
.. code-block:: pytest
$ pytest -s -q --tb=no
FFteardown smtp
@@ -454,12 +470,14 @@ read an optional server URL from the test module which uses our fixture::
server = getattr(request.module, "smtpserver", "smtp.gmail.com")
smtp_connection = smtplib.SMTP(server, 587, timeout=5)
yield smtp_connection
print ("finalizing %s (%s)" % (smtp_connection, server))
print("finalizing %s (%s)" % (smtp_connection, server))
smtp_connection.close()
We use the ``request.module`` attribute to optionally obtain an
``smtpserver`` attribute from the test module. If we just execute
again, nothing much has changed::
again, nothing much has changed:
.. code-block:: pytest
$ pytest -s -q --tb=no
FFfinalizing <smtplib.SMTP object at 0xdeadbeef> (smtp.gmail.com)
@@ -476,7 +494,9 @@ server URL in its module namespace::
def test_showhelo(smtp_connection):
assert 0, smtp_connection.helo()
Running it::
Running it:
.. code-block:: pytest
$ pytest -qq --tb=short test_anothersmtp.py
F [100%]
@@ -578,7 +598,9 @@ The main change is the declaration of ``params`` with
:py:func:`@pytest.fixture <_pytest.python.fixture>`, a list of values
for each of which the fixture function will execute and can access
a value via ``request.param``. No test function code needs to change.
So let's just do another run::
So let's just do another run:
.. code-block:: pytest
$ pytest -q test_module.py
FFFF [100%]
@@ -614,7 +636,7 @@ So let's just do another run::
response, msg = smtp_connection.ehlo()
assert response == 250
> assert b"smtp.gmail.com" in msg
E AssertionError: assert b'smtp.gmail.com' in b'mail.python.org\nPIPELINING\nSIZE 51200000\nETRN\nSTARTTLS\nAUTH DIGEST-MD5 NTLM CRAM-MD5\nENHANCEDSTATUSCODES\n8BITMIME\nDSN\nSMTPUTF8'
E AssertionError: assert b'smtp.gmail.com' in b'mail.python.org\nPIPELINING\nSIZE 51200000\nETRN\nSTARTTLS\nAUTH DIGEST-MD5 NTLM CRAM-MD5\nENHANCEDSTATUSCODES\n8BITMIME\nDSN\nSMTPUTF8\nCHUNKING'
test_module.py:5: AssertionError
-------------------------- Captured stdout setup ---------------------------
@@ -680,26 +702,29 @@ a function which will be called with the fixture value and then
has to return a string to use. In the latter case if the function
return ``None`` then pytest's auto-generated ID will be used.
Running the above tests results in the following test IDs being used::
Running the above tests results in the following test IDs being used:
.. code-block:: pytest
$ pytest --collect-only
=========================== test session starts ============================
platform linux -- Python 3.x.y, pytest-3.x.y, py-1.x.y, pluggy-0.x.y
rootdir: $REGENDOC_TMPDIR, inifile:
platform linux -- Python 3.x.y, pytest-4.x.y, py-1.x.y, pluggy-0.x.y
cachedir: $PYTHON_PREFIX/.pytest_cache
rootdir: $REGENDOC_TMPDIR
collected 10 items
<Module 'test_anothersmtp.py'>
<Function 'test_showhelo[smtp.gmail.com]'>
<Function 'test_showhelo[mail.python.org]'>
<Module 'test_ids.py'>
<Function 'test_a[spam]'>
<Function 'test_a[ham]'>
<Function 'test_b[eggs]'>
<Function 'test_b[1]'>
<Module 'test_module.py'>
<Function 'test_ehlo[smtp.gmail.com]'>
<Function 'test_noop[smtp.gmail.com]'>
<Function 'test_ehlo[mail.python.org]'>
<Function 'test_noop[mail.python.org]'>
<Module test_anothersmtp.py>
<Function test_showhelo[smtp.gmail.com]>
<Function test_showhelo[mail.python.org]>
<Module test_ids.py>
<Function test_a[spam]>
<Function test_a[ham]>
<Function test_b[eggs]>
<Function test_b[1]>
<Module test_module.py>
<Function test_ehlo[smtp.gmail.com]>
<Function test_noop[smtp.gmail.com]>
<Function test_ehlo[mail.python.org]>
<Function test_noop[mail.python.org]>
======================= no tests ran in 0.12 seconds =======================
@@ -722,13 +747,15 @@ Example::
def test_data(data_set):
pass
Running this test will *skip* the invocation of ``data_set`` with value ``2``::
Running this test will *skip* the invocation of ``data_set`` with value ``2``:
.. code-block:: pytest
$ pytest test_fixture_marks.py -v
=========================== test session starts ============================
platform linux -- Python 3.x.y, pytest-3.x.y, py-1.x.y, pluggy-0.x.y -- $PYTHON_PREFIX/bin/python3.6
cachedir: .pytest_cache
rootdir: $REGENDOC_TMPDIR, inifile:
platform linux -- Python 3.x.y, pytest-4.x.y, py-1.x.y, pluggy-0.x.y -- $PYTHON_PREFIX/bin/python
cachedir: $PYTHON_PREFIX/.pytest_cache
rootdir: $REGENDOC_TMPDIR
collecting ... collected 3 items
test_fixture_marks.py::test_data[0] PASSED [ 33%]
@@ -765,13 +792,15 @@ and instantiate an object ``app`` where we stick the already defined
assert app.smtp_connection
Here we declare an ``app`` fixture which receives the previously defined
``smtp_connection`` fixture and instantiates an ``App`` object with it. Let's run it::
``smtp_connection`` fixture and instantiates an ``App`` object with it. Let's run it:
.. code-block:: pytest
$ pytest -v test_appsetup.py
=========================== test session starts ============================
platform linux -- Python 3.x.y, pytest-3.x.y, py-1.x.y, pluggy-0.x.y -- $PYTHON_PREFIX/bin/python3.6
cachedir: .pytest_cache
rootdir: $REGENDOC_TMPDIR, inifile:
platform linux -- Python 3.x.y, pytest-4.x.y, py-1.x.y, pluggy-0.x.y -- $PYTHON_PREFIX/bin/python
cachedir: $PYTHON_PREFIX/.pytest_cache
rootdir: $REGENDOC_TMPDIR
collecting ... collected 2 items
test_appsetup.py::test_smtp_connection_exists[smtp.gmail.com] PASSED [ 50%]
@@ -784,7 +813,7 @@ different ``App`` instances and respective smtp servers. There is no
need for the ``app`` fixture to be aware of the ``smtp_connection``
parametrization because pytest will fully analyse the fixture dependency graph.
Note, that the ``app`` fixture has a scope of ``module`` and uses a
Note that the ``app`` fixture has a scope of ``module`` and uses a
module-scoped ``smtp_connection`` fixture. The example would still work if
``smtp_connection`` was cached on a ``session`` scope: it is fine for fixtures to use
"broader" scoped fixtures but not the other way round:
@@ -815,32 +844,34 @@ to show the setup/teardown flow::
@pytest.fixture(scope="module", params=["mod1", "mod2"])
def modarg(request):
param = request.param
print (" SETUP modarg %s" % param)
print(" SETUP modarg %s" % param)
yield param
print (" TEARDOWN modarg %s" % param)
print(" TEARDOWN modarg %s" % param)
@pytest.fixture(scope="function", params=[1,2])
def otherarg(request):
param = request.param
print (" SETUP otherarg %s" % param)
print(" SETUP otherarg %s" % param)
yield param
print (" TEARDOWN otherarg %s" % param)
print(" TEARDOWN otherarg %s" % param)
def test_0(otherarg):
print (" RUN test0 with otherarg %s" % otherarg)
print(" RUN test0 with otherarg %s" % otherarg)
def test_1(modarg):
print (" RUN test1 with modarg %s" % modarg)
print(" RUN test1 with modarg %s" % modarg)
def test_2(otherarg, modarg):
print (" RUN test2 with otherarg %s and modarg %s" % (otherarg, modarg))
print(" RUN test2 with otherarg %s and modarg %s" % (otherarg, modarg))
Let's run the tests in verbose mode and with looking at the print-output::
Let's run the tests in verbose mode and with looking at the print-output:
.. code-block:: pytest
$ pytest -v -s test_module.py
=========================== test session starts ============================
platform linux -- Python 3.x.y, pytest-3.x.y, py-1.x.y, pluggy-0.x.y -- $PYTHON_PREFIX/bin/python3.6
cachedir: .pytest_cache
rootdir: $REGENDOC_TMPDIR, inifile:
platform linux -- Python 3.x.y, pytest-4.x.y, py-1.x.y, pluggy-0.x.y -- $PYTHON_PREFIX/bin/python
cachedir: $PYTHON_PREFIX/.pytest_cache
rootdir: $REGENDOC_TMPDIR
collecting ... collected 8 items
test_module.py::test_0[1] SETUP otherarg 1
@@ -936,7 +967,9 @@ and declare its use in a test module via a ``usefixtures`` marker::
Due to the ``usefixtures`` marker, the ``cleandir`` fixture
will be required for the execution of each test method, just as if
you specified a "cleandir" function argument to each of them. Let's run it
to verify our fixture is activated and the tests pass::
to verify our fixture is activated and the tests pass:
.. code-block:: pytest
$ pytest -q
.. [100%]
@@ -1035,7 +1068,9 @@ which implies that all test methods in the class will use this fixture
without a need to state it in the test function signature or with a
class-level ``usefixtures`` decorator.
If we run it, we get two passing tests::
If we run it, we get two passing tests:
.. code-block:: pytest
$ pytest -q
.. [100%]

125
doc/en/flaky.rst Normal file
View File

@@ -0,0 +1,125 @@
Flaky tests
-----------
A "flaky" test is one that exhibits intermittent or sporadic failure, that seems to have non-deterministic behaviour. Sometimes it passes, sometimes it fails, and it's not clear why. This page discusses pytest features that can help and other general strategies for identifying, fixing or mitigating them.
Why flaky tests are a problem
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Flaky tests are particularly troublesome when a continuous integration (CI) server is being used, so that all tests must pass before a new code change can be merged. If the test result is not a reliable signal -- that a test failure means the code change broke the test -- developers can become mistrustful of the test results, which can lead to overlooking genuine failures. It is also a source of wasted time as developers must re-run test suites and investigate spurious failures.
Potential root causes
^^^^^^^^^^^^^^^^^^^^^
System state
~~~~~~~~~~~~
Broadly speaking, a flaky test indicates that the test relies on some system state that is not being appropriately controlled - the test environment is not sufficiently isolated. Higher level tests are more likely to be flaky as they rely on more state.
Flaky tests sometimes appear when a test suite is run in parallel (such as use of pytest-xdist). This can indicate a test is reliant on test ordering.
- Perhaps a different test is failing to clean up after itself and leaving behind data which causes the flaky test to fail.
- The flaky test is reliant on data from a previous test that doesn't clean up after itself, and in parallel runs that previous test is not always present
- Tests that modify global state typically cannot be run in parallel.
Overly strict assertion
~~~~~~~~~~~~~~~~~~~~~~~
Overly strict assertions can cause problems with floating point comparison as well as timing issues. `pytest.approx <https://docs.pytest.org/en/latest/reference.html#pytest-approx>`_ is useful here.
Pytest features
^^^^^^^^^^^^^^^
Xfail strict
~~~~~~~~~~~~
:ref:`pytest.mark.xfail ref` with ``strict=False`` can be used to mark a test so that its failure does not cause the whole build to break. This could be considered like a manual quarantine, and is rather dangerous to use permanently.
PYTEST_CURRENT_TEST
~~~~~~~~~~~~~~~~~~~
:ref:`pytest current test env` may be useful for figuring out "which test got stuck".
Plugins
~~~~~~~
Rerunning any failed tests can mitigate the negative effects of flaky tests by giving them additional chances to pass, so that the overall build does not fail. Several pytest plugins support this:
* `flaky <https://github.com/box/flaky>`_
* `pytest-flakefinder <https://github.com/dropbox/pytest-flakefinder>`_ - `blog post <https://blogs.dropbox.com/tech/2016/03/open-sourcing-pytest-tools/>`_
* `pytest-rerunfailures <https://github.com/pytest-dev/pytest-rerunfailures>`_
* `pytest-replay <https://github.com/ESSS/pytest-replay>`_: This plugin helps to reproduce locally crashes or flaky tests observed during CI runs.
Plugins to deliberately randomize tests can help expose tests with state problems:
* `pytest-random-order <https://github.com/jbasko/pytest-random-order>`_
* `pytest-randomly <https://github.com/pytest-dev/pytest-randomly>`_
Other general strategies
^^^^^^^^^^^^^^^^^^^^^^^^
Split up test suites
~~~~~~~~~~~~~~~~~~~~
It can be common to split a single test suite into two, such as unit vs integration, and only use the unit test suite as a CI gate. This also helps keep build times manageable as high level tests tend to be slower. However, it means it does become possible for code that breaks the build to be merged, so extra vigilance is needed for monitoring the integration test results.
Video/screenshot on failure
~~~~~~~~~~~~~~~~~~~~~~~~~~~
For UI tests these are important for understanding what the state of the UI was when the test failed. pytest-splinter can be used with plugins like pytest-bdd and can `save a screenshot on test failure <https://pytest-splinter.readthedocs.io/en/latest/#automatic-screenshots-on-test-failure>`_, which can help to isolate the cause.
Delete or rewrite the test
~~~~~~~~~~~~~~~~~~~~~~~~~~
If the functionality is covered by other tests, perhaps the test can be removed. If not, perhaps it can be rewritten at a lower level which will remove the flakiness or make its source more apparent.
Quarantine
~~~~~~~~~~
Mark Lapierre discusses the `Pros and Cons of Quarantined Tests <https://dev.to/mlapierre/pros-and-cons-of-quarantined-tests-2emj>`_ in a post from 2018.
CI tools that rerun on failure
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Azure Pipelines (the Azure cloud CI/CD tool, formerly Visual Studio Team Services or VSTS) has a feature to `identify flaky tests <https://docs.microsoft.com/en-us/azure/devops/release-notes/2017/dec-11-vsts#identify-flaky-tests>`_ and rerun failed tests.
Research
^^^^^^^^
This is a limited list, please submit an issue or pull request to expand it!
* Gao, Zebao, Yalan Liang, Myra B. Cohen, Atif M. Memon, and Zhen Wang. "Making system user interactive tests repeatable: When and what should we control?." In *Software Engineering (ICSE), 2015 IEEE/ACM 37th IEEE International Conference on*, vol. 1, pp. 55-65. IEEE, 2015. `PDF <http://www.cs.umd.edu/~atif/pubs/gao-icse15.pdf>`__
* Palomba, Fabio, and Andy Zaidman. "Does refactoring of test smells induce fixing flaky tests?." In *Software Maintenance and Evolution (ICSME), 2017 IEEE International Conference on*, pp. 1-12. IEEE, 2017. `PDF in Google Drive <https://drive.google.com/file/d/10HdcCQiuQVgW3yYUJD-TSTq1NbYEprl0/view>`__
* Bell, Jonathan, Owolabi Legunsen, Michael Hilton, Lamyaa Eloussi, Tifany Yung, and Darko Marinov. "DeFlaker: Automatically detecting flaky tests." In *Proceedings of the 2018 International Conference on Software Engineering*. 2018. `PDF <https://www.jonbell.net/icse18-deflaker.pdf>`__
Resources
^^^^^^^^^
* `Eradicating Non-Determinism in Tests <https://martinfowler.com/articles/nonDeterminism.html>`_ by Martin Fowler, 2011
* `No more flaky tests on the Go team <https://www.thoughtworks.com/insights/blog/no-more-flaky-tests-go-team>`_ by Pavan Sudarshan, 2012
* `The Build That Cried Broken: Building Trust in your Continuous Integration Tests <https://www.youtube.com/embed/VotJqV4n8ig>`_ talk (video) by `Angie Jones <http://angiejones.tech/>`_ at SeleniumConf Austin 2017
* `Test and Code Podcast: Flaky Tests and How to Deal with Them <https://testandcode.com/50>`_ by Brian Okken and Anthony Shaw, 2018
* Microsoft:
* `How we approach testing VSTS to enable continuous delivery <https://blogs.msdn.microsoft.com/bharry/2017/06/28/testing-in-a-cloud-delivery-cadence/>`_ by Brian Harry MS, 2017
* `Eliminating Flaky Tests <https://docs.microsoft.com/en-us/azure/devops/learn/devops-at-microsoft/eliminating-flaky-tests>`_ blog and talk (video) by Munil Shah, 2017
* Google:
* `Flaky Tests at Google and How We Mitigate Them <https://testing.googleblog.com/2016/05/flaky-tests-at-google-and-how-we.html>`_ by John Micco, 2016
* `Where do Google's flaky tests come from? <https://docs.google.com/document/d/1mZ0-Kc97DI_F3tf_GBW_NB_aqka-P1jVOsFfufxqUUM/edit#heading=h.ec0r4fypsleh>`_ by Jeff Listfield, 2017

View File

@@ -7,7 +7,7 @@ pytest-2.3: reasoning for fixture/funcarg evolution
**Target audience**: Reading this document requires basic knowledge of
python testing, xUnit setup methods and the (previous) basic pytest
funcarg mechanism, see http://pytest.org/2.2.4/funcargs.html
funcarg mechanism, see https://docs.pytest.org/en/latest/historical-notes.html#funcargs-and-pytest-funcarg.
If you are new to pytest, then you can simply ignore this
section and read the other sections.
@@ -26,9 +26,9 @@ a per-session Database object::
# content of conftest.py
class Database(object):
def __init__(self):
print ("database instance created")
print("database instance created")
def destroy(self):
print ("database instance destroyed")
print("database instance destroyed")
def pytest_funcarg__db(request):
return request.cached_setup(setup=DataBase,

View File

@@ -1,15 +1,12 @@
Installation and Getting Started
===================================
**Pythons**: Python 2.7, 3.4, 3.5, 3.6, Jython, PyPy-2.3
**Pythons**: Python 2.7, 3.4, 3.5, 3.6, 3.7, Jython, PyPy-2.3
**Platforms**: Unix/Posix and Windows
**PyPI package name**: `pytest <https://pypi.org/project/pytest/>`_
**Dependencies**: `py <https://pypi.org/project/py/>`_,
`colorama (Windows) <https://pypi.org/project/colorama/>`_,
**Documentation as PDF**: `download latest <https://media.readthedocs.org/pdf/pytest/latest/pytest.pdf>`_
``pytest`` is a framework that makes building simple and scalable tests easy. Tests are expressive and readable—no boilerplate code required. Get started in minutes with a small unit test or complex functional test for your application or library.
@@ -20,14 +17,18 @@ Installation and Getting Started
Install ``pytest``
----------------------------------------
1. Run the following command in your command line::
1. Run the following command in your command line:
.. code-block:: bash
pip install -U pytest
2. Check that you installed the correct version::
2. Check that you installed the correct version:
.. code-block:: bash
$ pytest --version
This is pytest version 3.x.y, imported from $PYTHON_PREFIX/lib/python3.6/site-packages/pytest.py
This is pytest version 4.x.y, imported from $PYTHON_PREFIX/lib/python3.6/site-packages/pytest.py
.. _`simpletest`:
@@ -43,12 +44,15 @@ Create a simple test function with just four lines of code::
def test_answer():
assert func(3) == 5
Thats it. You can now execute the test function::
Thats it. You can now execute the test function:
.. code-block:: pytest
$ pytest
=========================== test session starts ============================
platform linux -- Python 3.x.y, pytest-3.x.y, py-1.x.y, pluggy-0.x.y
rootdir: $REGENDOC_TMPDIR, inifile:
platform linux -- Python 3.x.y, pytest-4.x.y, py-1.x.y, pluggy-0.x.y
cachedir: $PYTHON_PREFIX/.pytest_cache
rootdir: $REGENDOC_TMPDIR
collected 1 item
test_sample.py F [100%]
@@ -79,7 +83,7 @@ Run multiple tests
Assert that a certain exception is raised
--------------------------------------------------------------
Use the ``raises`` helper to assert that some code raises an exception::
Use the :ref:`raises <assertraises>` helper to assert that some code raises an exception::
# content of test_sysexit.py
import pytest
@@ -90,7 +94,9 @@ Use the ``raises`` helper to assert that some code raises an exception::
with pytest.raises(SystemExit):
f()
Execute the test function with “quiet” reporting mode::
Execute the test function with “quiet” reporting mode:
.. code-block:: pytest
$ pytest -q test_sysexit.py
. [100%]
@@ -111,7 +117,9 @@ Once you develop multiple tests, you may want to group them into a class. pytest
x = "hello"
assert hasattr(x, 'check')
``pytest`` discovers all tests following its :ref:`Conventions for Python test discovery <test discovery>`, so it finds both ``test_`` prefixed functions. There is no need to subclass anything. We can simply run the module by passing its filename::
``pytest`` discovers all tests following its :ref:`Conventions for Python test discovery <test discovery>`, so it finds both ``test_`` prefixed functions. There is no need to subclass anything. We can simply run the module by passing its filename:
.. code-block:: pytest
$ pytest -q test_class.py
.F [100%]
@@ -138,10 +146,12 @@ Request a unique temporary directory for functional tests
# content of test_tmpdir.py
def test_needsfiles(tmpdir):
print (tmpdir)
print(tmpdir)
assert 0
List the name ``tmpdir`` in the test function signature and ``pytest`` will lookup and call a fixture factory to create the resource before performing the test function call. Before the test runs, ``pytest`` creates a unique-per-test-invocation temporary directory::
List the name ``tmpdir`` in the test function signature and ``pytest`` will lookup and call a fixture factory to create the resource before performing the test function call. Before the test runs, ``pytest`` creates a unique-per-test-invocation temporary directory:
.. code-block:: pytest
$ pytest -q test_tmpdir.py
F [100%]
@@ -151,7 +161,7 @@ List the name ``tmpdir`` in the test function signature and ``pytest`` will look
tmpdir = local('PYTEST_TMPDIR/test_needsfiles0')
def test_needsfiles(tmpdir):
print (tmpdir)
print(tmpdir)
> assert 0
E assert 0
@@ -162,7 +172,9 @@ List the name ``tmpdir`` in the test function signature and ``pytest`` will look
More info on tmpdir handling is available at :ref:`Temporary directories and files <tmpdir handling>`.
Find out what kind of builtin :ref:`pytest fixtures <fixtures>` exist with the command::
Find out what kind of builtin :ref:`pytest fixtures <fixtures>` exist with the command:
.. code-block:: bash
pytest --fixtures # shows builtin and custom fixtures

View File

@@ -4,6 +4,28 @@
Good Integration Practices
=================================================
Install package with pip
-------------------------------------------------
For development, we recommend you use venv_ for virtual environments
(or virtualenv_ for Python 2.7) and
pip_ for installing your application and any dependencies,
as well as the ``pytest`` package itself.
This ensures your code and dependencies are isolated from your system Python installation.
Next, place a ``setup.py`` file in the root of your package with the following minimum content::
from setuptools import setup, find_packages
setup(name="PACKAGENAME", packages=find_packages())
Where ``PACKAGENAME`` is the name of your package. You can then install your package in "editable" mode by running from the same directory::
pip install -e .
which lets you change your source code (both tests and application) and rerun tests at will.
This is similar to running ``python setup.py develop`` or ``conda develop`` in that it installs
your package using a symlink to your development code.
.. _`test discovery`:
.. _`Python test discovery`:
@@ -20,8 +42,8 @@ Conventions for Python test discovery
* In those directories, search for ``test_*.py`` or ``*_test.py`` files, imported by their `test package name`_.
* From those files, collect test items:
* ``test_`` prefixed test functions or methods outside of class
* ``test_`` prefixed test functions or methods inside ``Test`` prefixed test classes (without an ``__init__`` method)
* ``test`` prefixed test functions or methods outside of class
* ``test`` prefixed test functions or methods inside ``Test`` prefixed test classes (without an ``__init__`` method)
For examples of how to customize your test discovery :doc:`example/pythoncollection`.
@@ -51,8 +73,18 @@ to keep tests separate from actual application code (often a good idea)::
test_view.py
...
This way your tests can run easily against an installed version
of ``mypkg``.
This has the following benefits:
* Your tests can run against an installed version after executing ``pip install .``.
* Your tests can run against the local copy with an editable install after executing ``pip install --editable .``.
* If you don't have a ``setup.py`` file and are relying on the fact that Python by default puts the current
directory in ``sys.path`` to import your package, you can execute ``python -m pytest`` to execute the tests against the
local copy directly, without using ``pip``.
.. note::
See :ref:`pythonpath` for more information about the difference between calling ``pytest`` and
``python -m pytest``.
Note that using this scheme your test files must have **unique names**, because
``pytest`` will import them as *top-level* modules since there are no packages
@@ -177,19 +209,6 @@ Note that this layout also works in conjunction with the ``src`` layout mentione
tox
------
For development, we recommend to use virtualenv_ environments and pip_
for installing your application and any dependencies
as well as the ``pytest`` package itself. This ensures your code and
dependencies are isolated from the system Python installation.
You can then install your package in "editable" mode::
pip install -e .
which lets you change your source code (both tests and application) and rerun tests at will.
This is similar to running ``python setup.py develop`` or ``conda develop`` in that it installs
your package using a symlink to your development code.
Once you are done with your work and want to make sure that your actual
package passes all tests you may want to look into `tox`_, the
virtualenv test automation tool and its `pytest support
@@ -282,7 +301,7 @@ your own setuptools Test command for invoking pytest.
setup(
# ...,
tests_require=["pytest"],
cmdclass={"test": PyTest},
cmdclass={"pytest": PyTest},
)
Now if you run::

View File

@@ -7,7 +7,7 @@ kept here as a historical note so users looking at old code can find documentati
cache plugin integrated into the core
-------------------------------------
.. versionadded:: 2.8
The functionality of the :ref:`core cache <cache>` plugin was previously distributed
as a third party plugin named ``pytest-cache``. The core plugin
@@ -18,7 +18,7 @@ can only store/receive data between test runs that is json-serializable.
funcargs and ``pytest_funcarg__``
---------------------------------
.. versionchanged:: 2.3
In versions prior to 2.3 there was no ``@pytest.fixture`` marker
and you had to use a magic ``pytest_funcarg__NAME`` prefix
@@ -30,7 +30,7 @@ functions.
``@pytest.yield_fixture`` decorator
-----------------------------------
.. versionchanged:: 2.10
Prior to version 2.10, in order to use a ``yield`` statement to execute teardown code one
had to mark a fixture using the ``yield_fixture`` marker. From 2.10 onward, normal
@@ -41,7 +41,7 @@ and considered deprecated.
``[pytest]`` header in ``setup.cfg``
------------------------------------
.. versionchanged:: 3.0
Prior to 3.0, the supported section name was ``[pytest]``. Due to how
this may collide with some distutils commands, the recommended
@@ -54,17 +54,19 @@ name is ``[pytest]``.
Applying marks to ``@pytest.mark.parametrize`` parameters
---------------------------------------------------------
.. versionchanged:: 3.1
Prior to version 3.1 the supported mechanism for marking values
used the syntax::
used the syntax:
.. code-block:: python
import pytest
@pytest.mark.parametrize("test_input,expected", [
("3+5", 8),
("2+4", 6),
pytest.mark.xfail(("6*9", 42),),
])
@pytest.mark.parametrize(
"test_input,expected", [("3+5", 8), ("2+4", 6), pytest.mark.xfail(("6*9", 42))]
)
def test_eval(test_input, expected):
assert eval(test_input) == expected
@@ -78,7 +80,7 @@ The old syntax is planned to be removed in pytest-4.0.
``@pytest.mark.parametrize`` argument names as a tuple
------------------------------------------------------
.. versionchanged:: 2.4
In versions prior to 2.4 one needed to specify the argument
names as a tuple. This remains valid but the simpler ``"name1,name2,..."``
@@ -89,7 +91,7 @@ it's easier to write and produces less line noise.
setup: is now an "autouse fixture"
----------------------------------
.. versionchanged:: 2.3
During development prior to the pytest-2.3 release the name
``pytest.setup`` was used but before the release it was renamed
@@ -102,12 +104,16 @@ namely :ref:`autouse fixtures`
Conditions as strings instead of booleans
-----------------------------------------
.. versionchanged:: 2.4
Prior to pytest-2.4 the only way to specify skipif/xfail conditions was
to use strings::
to use strings:
.. code-block:: python
import sys
@pytest.mark.skipif("sys.version_info >= (3,3)")
def test_function():
...
@@ -139,17 +145,20 @@ dictionary which is constructed as follows:
expression is applied.
The pytest ``config`` object allows you to skip based on a test
configuration value which you might have added::
configuration value which you might have added:
.. code-block:: python
@pytest.mark.skipif("not config.getvalue('db')")
def test_function(...):
def test_function():
...
The equivalent with "boolean conditions" is::
The equivalent with "boolean conditions" is:
@pytest.mark.skipif(not pytest.config.getvalue("db"),
reason="--db was not specified")
def test_function(...):
.. code-block:: python
@pytest.mark.skipif(not pytest.config.getvalue("db"), reason="--db was not specified")
def test_function():
pass
.. note::
@@ -162,16 +171,30 @@ The equivalent with "boolean conditions" is::
``pytest.set_trace()``
----------------------
.. versionchanged:: 2.4
Previous to version 2.4 to set a break point in code one needed to use ``pytest.set_trace()``::
Previous to version 2.4 to set a break point in code one needed to use ``pytest.set_trace()``:
.. code-block:: python
import pytest
def test_function():
...
pytest.set_trace() # invoke PDB debugger and tracing
pytest.set_trace() # invoke PDB debugger and tracing
This is no longer needed and one can use the native ``import pdb;pdb.set_trace()`` call directly.
For more details see :ref:`breakpoints`.
"compat" properties
-------------------
Access of ``Module``, ``Function``, ``Class``, ``Instance``, ``File`` and ``Item`` through ``Node`` instances have long
been documented as deprecated, but started to emit warnings from pytest ``3.9`` and onward.
Users should just ``import pytest`` and access those objects using the ``pytest`` module.

View File

@@ -22,12 +22,15 @@ An example of a simple test:
assert inc(3) == 5
To execute it::
To execute it:
.. code-block:: pytest
$ pytest
=========================== test session starts ============================
platform linux -- Python 3.x.y, pytest-3.x.y, py-1.x.y, pluggy-0.x.y
rootdir: $REGENDOC_TMPDIR, inifile:
platform linux -- Python 3.x.y, pytest-4.x.y, py-1.x.y, pluggy-0.x.y
cachedir: $PYTHON_PREFIX/.pytest_cache
rootdir: $REGENDOC_TMPDIR
collected 1 item
test_sample.py F [100%]

View File

@@ -5,7 +5,7 @@ License
Distributed under the terms of the `MIT`_ license, pytest is free and open source software.
::
.. code-block:: text
The MIT License (MIT)

View File

@@ -14,6 +14,7 @@
.. _`distribute docs`:
.. _`distribute`: https://pypi.org/project/distribute/
.. _`pip`: https://pypi.org/project/pip/
.. _`venv`: https://docs.python.org/3/library/venv.html/
.. _`virtualenv`: https://pypi.org/project/virtualenv/
.. _hudson: http://hudson-ci.org/
.. _jenkins: http://jenkins-ci.org/

View File

@@ -3,17 +3,21 @@
Logging
-------
.. versionadded:: 3.3
.. versionchanged:: 3.4
pytest captures log messages of level ``WARNING`` or above automatically and displays them in their own section
for each failed test in the same manner as captured stdout and stderr.
Running without options::
Running without options:
.. code-block:: bash
pytest
Shows failed tests like so::
Shows failed tests like so:
.. code-block:: pytest
----------------------- Captured stdlog call ----------------------
test_reporting.py 26 WARNING text going to logger
@@ -27,12 +31,16 @@ By default each captured log message shows the module, line number, log level
and message.
If desired the log and date format can be specified to
anything that the logging module supports by passing specific formatting options::
anything that the logging module supports by passing specific formatting options:
.. code-block:: bash
pytest --log-format="%(asctime)s %(levelname)s %(message)s" \
--log-date-format="%Y-%m-%d %H:%M:%S"
Shows failed tests like so::
Shows failed tests like so:
.. code-block:: pytest
----------------------- Captured stdlog call ----------------------
2010-04-10 14:48:44 WARNING text going to logger
@@ -51,7 +59,9 @@ These options can also be customized through ``pytest.ini`` file:
log_date_format = %Y-%m-%d %H:%M:%S
Further it is possible to disable reporting of captured content (stdout,
stderr and logs) on failed tests completely with::
stderr and logs) on failed tests completely with:
.. code-block:: bash
pytest --show-capture=no
@@ -133,7 +143,6 @@ the records for the ``setup`` and ``call`` stages during teardown like so:
.. code-block:: python
@pytest.fixture
def window(caplog):
window = create_window()
@@ -198,6 +207,9 @@ option names are:
* ``log_file_format``
* ``log_file_date_format``
You can call ``set_log_path()`` to customize the log_file path dynamically. This functionality
is considered **experimental**.
.. _log_release_notes:
Release notes

View File

@@ -29,9 +29,11 @@ which also serve as documentation.
Raising errors on unknown marks: --strict
-----------------------------------------
When the ``--strict`` command-line flag is passed, any marks not registered in the ``pytest.ini`` file will trigger an error.
When the ``--strict`` command-line flag is passed, any unknown marks applied
with the ``@pytest.mark.name_of_the_mark`` decorator will trigger an error.
Marks defined or added by pytest or by a plugin will not trigger an error.
Marks can be registered like this:
Marks can be registered in ``pytest.ini`` like this:
.. code-block:: ini
@@ -52,10 +54,12 @@ should add ``--strict`` to ``addopts``:
serial
.. _marker-revamp:
Marker revamp and iteration
---------------------------
.. versionadded:: 3.6
pytest's marker implementation traditionally worked by simply updating the ``__dict__`` attribute of functions to cumulatively add markers. As a result, markers would unintentionally be passed along class hierarchies in surprising ways. Further, the API for retrieving them was inconsistent, as markers from parameterization would be stored differently than markers applied using the ``@pytest.mark`` decorator and markers added via ``node.add_marker``.
@@ -154,4 +158,4 @@ More details can be found in the `original PR <https://github.com/pytest-dev/pyt
.. note::
in a future major relase of pytest we will introduce class based markers,
at which points markers will no longer be limited to instances of :py:class:`Mark`
at which point markers will no longer be limited to instances of :py:class:`Mark`

View File

@@ -12,7 +12,9 @@ Running tests written for nose
Usage
-------------
After :ref:`installation` type::
After :ref:`installation` type:
.. code-block:: bash
python setup.py develop # make sure tests can import our package
pytest # instead of 'nosetests'

View File

@@ -29,33 +29,36 @@ pytest enables test parametrization at several levels:
.. regendoc: wipe
.. versionadded:: 2.2
.. versionchanged:: 2.4
Several improvements.
The builtin :ref:`pytest.mark.parametrize ref` decorator enables
parametrization of arguments for a test function. Here is a typical example
of a test function that implements checking that a certain input leads
to an expected output::
to an expected output:
.. code-block:: python
# content of test_expectation.py
import pytest
@pytest.mark.parametrize("test_input,expected", [
("3+5", 8),
("2+4", 6),
("6*9", 42),
])
@pytest.mark.parametrize("test_input,expected", [("3+5", 8), ("2+4", 6), ("6*9", 42)])
def test_eval(test_input, expected):
assert eval(test_input) == expected
Here, the ``@parametrize`` decorator defines three different ``(test_input,expected)``
tuples so that the ``test_eval`` function will run three times using
them in turn::
them in turn:
.. code-block:: pytest
$ pytest
=========================== test session starts ============================
platform linux -- Python 3.x.y, pytest-3.x.y, py-1.x.y, pluggy-0.x.y
rootdir: $REGENDOC_TMPDIR, inifile:
platform linux -- Python 3.x.y, pytest-4.x.y, py-1.x.y, pluggy-0.x.y
cachedir: $PYTHON_PREFIX/.pytest_cache
rootdir: $REGENDOC_TMPDIR
collected 3 items
test_expectation.py ..F [100%]
@@ -65,19 +68,30 @@ them in turn::
test_input = '6*9', expected = 42
@pytest.mark.parametrize("test_input,expected", [
("3+5", 8),
("2+4", 6),
("6*9", 42),
])
@pytest.mark.parametrize("test_input,expected", [("3+5", 8), ("2+4", 6), ("6*9", 42)])
def test_eval(test_input, expected):
> assert eval(test_input) == expected
E AssertionError: assert 54 == 42
E + where 54 = eval('6*9')
test_expectation.py:8: AssertionError
test_expectation.py:6: AssertionError
==================== 1 failed, 2 passed in 0.12 seconds ====================
.. note::
pytest by default escapes any non-ascii characters used in unicode strings
for the parametrization because it has several downsides.
If however you would like to use unicode strings in parametrization and see them in the terminal as is (non-escaped), use this option in your ``pytest.ini``:
.. code-block:: ini
[pytest]
disable_test_id_escaping_and_forfeit_all_rights_to_community_support = True
Keep in mind however that this might cause unwanted side effects and
even bugs depending on the OS used and plugins currently installed, so use it at your own risk.
As designed in this example, only one pair of input/output values fails
the simple test function. And as usual with test function arguments,
you can see the ``input`` and ``output`` values in the traceback.
@@ -86,25 +100,30 @@ Note that you could also use the parametrize marker on a class or a module
(see :ref:`mark`) which would invoke several functions with the argument sets.
It is also possible to mark individual test instances within parametrize,
for example with the builtin ``mark.xfail``::
for example with the builtin ``mark.xfail``:
.. code-block:: python
# content of test_expectation.py
import pytest
@pytest.mark.parametrize("test_input,expected", [
("3+5", 8),
("2+4", 6),
pytest.param("6*9", 42,
marks=pytest.mark.xfail),
])
@pytest.mark.parametrize(
"test_input,expected",
[("3+5", 8), ("2+4", 6), pytest.param("6*9", 42, marks=pytest.mark.xfail)],
)
def test_eval(test_input, expected):
assert eval(test_input) == expected
Let's run this::
Let's run this:
.. code-block:: pytest
$ pytest
=========================== test session starts ============================
platform linux -- Python 3.x.y, pytest-3.x.y, py-1.x.y, pluggy-0.x.y
rootdir: $REGENDOC_TMPDIR, inifile:
platform linux -- Python 3.x.y, pytest-4.x.y, py-1.x.y, pluggy-0.x.y
cachedir: $PYTHON_PREFIX/.pytest_cache
rootdir: $REGENDOC_TMPDIR
collected 3 items
test_expectation.py ..x [100%]
@@ -114,10 +133,18 @@ Let's run this::
The one parameter set which caused a failure previously now
shows up as an "xfailed (expected to fail)" test.
In case the values provided to ``parametrize`` result in an empty list - for
example, if they're dynamically generated by some function - the behaviour of
pytest is defined by the :confval:`empty_parameter_set_mark` option.
To get all combinations of multiple parametrized arguments you can stack
``parametrize`` decorators::
``parametrize`` decorators:
.. code-block:: python
import pytest
@pytest.mark.parametrize("x", [0, 1])
@pytest.mark.parametrize("y", [2, 3])
def test_foo(x, y):
@@ -141,34 +168,48 @@ parametrization.
For example, let's say we want to run a test taking string inputs which
we want to set via a new ``pytest`` command line option. Let's first write
a simple test accepting a ``stringinput`` fixture function argument::
a simple test accepting a ``stringinput`` fixture function argument:
.. code-block:: python
# content of test_strings.py
def test_valid_string(stringinput):
assert stringinput.isalpha()
Now we add a ``conftest.py`` file containing the addition of a
command line option and the parametrization of our test function::
command line option and the parametrization of our test function:
.. code-block:: python
# content of conftest.py
def pytest_addoption(parser):
parser.addoption("--stringinput", action="append", default=[],
help="list of stringinputs to pass to test functions")
parser.addoption(
"--stringinput",
action="append",
default=[],
help="list of stringinputs to pass to test functions",
)
def pytest_generate_tests(metafunc):
if 'stringinput' in metafunc.fixturenames:
metafunc.parametrize("stringinput",
metafunc.config.getoption('stringinput'))
if "stringinput" in metafunc.fixturenames:
metafunc.parametrize("stringinput", metafunc.config.getoption("stringinput"))
If we now pass two stringinput values, our test will run twice::
If we now pass two stringinput values, our test will run twice:
.. code-block:: pytest
$ pytest -q --stringinput="hello" --stringinput="world" test_strings.py
.. [100%]
2 passed in 0.12 seconds
Let's also run with a stringinput that will lead to a failing test::
Let's also run with a stringinput that will lead to a failing test:
.. code-block:: pytest
$ pytest -q --stringinput="!" test_strings.py
F [100%]
@@ -183,19 +224,21 @@ Let's also run with a stringinput that will lead to a failing test::
E + where False = <built-in method isalpha of str object at 0xdeadbeef>()
E + where <built-in method isalpha of str object at 0xdeadbeef> = '!'.isalpha
test_strings.py:3: AssertionError
test_strings.py:4: AssertionError
1 failed in 0.12 seconds
As expected our test function fails.
If you don't specify a stringinput it will be skipped because
``metafunc.parametrize()`` will be called with an empty parameter
list::
list:
.. code-block:: pytest
$ pytest -q -rs test_strings.py
s [100%]
========================= short test summary info ==========================
SKIP [1] test_strings.py: got empty parameter set ['stringinput'], function test_valid_string at $REGENDOC_TMPDIR/test_strings.py:1
SKIPPED [1] test_strings.py: got empty parameter set ['stringinput'], function test_valid_string at $REGENDOC_TMPDIR/test_strings.py:2
1 skipped in 0.12 seconds
Note that when calling ``metafunc.parametrize`` multiple times with different parameter sets, all parameter names across

View File

@@ -27,7 +27,7 @@ Here is a little annotated list for some popular plugins:
for `twisted <http://twistedmatrix.com>`_ apps, starting a reactor and
processing deferreds from test functions.
* `pytest-cov <https://pypi.org/project/pytest-cov/>`_:
* `pytest-cov <https://pypi.org/project/pytest-cov/>`__:
coverage reporting, compatible with distributed testing
* `pytest-xdist <https://pypi.org/project/pytest-xdist/>`_:
@@ -59,9 +59,9 @@ To see a complete list of all plugins with their latest testing
status against different pytest and Python versions, please visit
`plugincompat <http://plugincompat.herokuapp.com/>`_.
You may also discover more plugins through a `pytest- pypi.python.org search`_.
You may also discover more plugins through a `pytest- pypi.org search`_.
.. _`pytest- pypi.python.org search`: https://pypi.org/search/?q=pytest-
.. _`pytest- pypi.org search`: https://pypi.org/search/?q=pytest-
.. _`available installable plugins`:
@@ -69,23 +69,26 @@ You may also discover more plugins through a `pytest- pypi.python.org search`_.
Requiring/Loading plugins in a test module or conftest file
-----------------------------------------------------------
You can require plugins in a test module or a conftest file like this::
You can require plugins in a test module or a conftest file like this:
pytest_plugins = "myapp.testsupport.myplugin",
.. code-block:: python
pytest_plugins = ("myapp.testsupport.myplugin",)
When the test module or conftest plugin is loaded the specified plugins
will be loaded as well.
pytest_plugins = "myapp.testsupport.myplugin"
which will import the specified module as a ``pytest`` plugin.
.. note::
Requiring plugins using a ``pytest_plugins`` variable in non-root
``conftest.py`` files is deprecated. See
:ref:`full explanation <requiring plugins in non-root conftests>`
in the Writing plugins section.
.. note::
The name ``pytest_plugins`` is reserved and should not be used as a
name for a custom plugin module.
.. _`findpluginname`:
Finding out which plugins are active

View File

@@ -75,7 +75,7 @@ Issues
------
* By using ``request.getfuncargvalue()`` we rely on actual fixture function
execution to know what fixtures are involved, due to it's dynamic nature
execution to know what fixtures are involved, due to its dynamic nature
* More importantly, ``request.getfuncargvalue()`` cannot be combined with
parametrized fixtures, such as ``extra_context``
* This is very inconvenient if you wish to extend an existing test suite by

View File

@@ -0,0 +1,22 @@
Python 2.7 and 3.4 support plan
===============================
Python 2.7 EOL is fast approaching, with
upstream support `ending in 2020 <https://legacy.python.org/dev/peps/pep-0373/#id4>`__.
Python 3.4's last release is scheduled for
`March 2019 <https://www.python.org/dev/peps/pep-0429/#release-schedule>`__. pytest is one of
the participating projects of the https://python3statement.org.
We plan to drop support for Python 2.7 and 3.4 at the same time with the release of **pytest 5.0**,
scheduled to be released by **mid-2019**. Thanks to the `python_requires <https://packaging.python.org/guides/distributing-packages-using-setuptools/#python-requires>`__ ``setuptools`` option,
Python 2.7 and Python 3.4 users using a modern ``pip`` version
will install the last compatible pytest ``4.X`` version automatically even if ``5.0`` or later
are available on PyPI.
During the period **from mid-2019 and 2020**, the pytest core team plans to make
bug-fix releases of the pytest ``4.X`` series by back-porting patches to the ``4.x-maintenance``
branch.
**After 2020**, the core team will no longer actively back port-patches, but the ``4.x-maintenance``
branch will continue to exist so the community itself can contribute patches. The
core team will be happy to accept those patches and make new ``4.X`` releases **until mid-2020**.

View File

@@ -1,4 +1,3 @@
Reference
=========
@@ -49,7 +48,7 @@ pytest.main
.. autofunction:: _pytest.config.main
pytest.param
~~~~~~~~~~~~~
~~~~~~~~~~~~
.. autofunction:: pytest.param(*values, [id], [marks])
@@ -84,6 +83,12 @@ pytest.warns
.. autofunction:: pytest.warns(expected_warning: Exception, [match])
:with:
pytest.freeze_includes
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
**Tutorial**: :ref:`freezing-pytest`.
.. autofunction:: pytest.freeze_includes
.. _`marks ref`:
@@ -111,6 +116,7 @@ Add warning filters to marked test items.
A *warning specification string*, which is composed of contents of the tuple ``(action, message, category, module, lineno)``
as specified in `The Warnings filter <https://docs.python.org/3/library/warnings.html#warning-filter>`_ section of
the Python documentation, separated by ``":"``. Optional fields can be omitted.
Module names passed for filtering are not regex-escaped.
For example:
@@ -172,7 +178,7 @@ Mark a test function as using the given fixture names.
.. warning::
This mark can be used with *test functions* only, having no affect when applied
This mark has no effect when applied
to a **fixture** function.
.. py:function:: pytest.mark.usefixtures(*names)
@@ -192,16 +198,18 @@ Marks a test function as *expected to fail*.
.. py:function:: pytest.mark.xfail(condition=None, *, reason=None, raises=None, run=True, strict=False)
:type condition: bool or str
:param condition: ``True/False`` if the condition should be marked as xfail or a :ref:`condition string <string conditions>`.
:param condition:
Condition for marking the test function as xfail (``True/False`` or a
:ref:`condition string <string conditions>`).
:keyword str reason: Reason why the test function is marked as xfail.
:keyword Exception raises: Exception subclass expected to be raised by the test function; other exceptions will fail the test.
:keyword bool run:
If the test function should actually be executed. If ``False``, the function will always xfail and will
not be executed (useful a function is segfaulting).
not be executed (useful if a function is segfaulting).
:keyword bool strict:
* If ``False`` (the default) the function will be shown in the terminal output as ``xfailed`` if it fails
and as ``xpass`` if it passes. In both cases this will not cause the test suite to fail as a whole. This
is particularly useful to mark *flaky* tests (tests that random at fail) to be tackled later.
is particularly useful to mark *flaky* tests (tests that fail at random) to be tackled later.
* If ``True``, the function will be shown in the terminal output as ``xfailed`` if it fails, but if it
unexpectedly passes then it will **fail** the test suite. This is particularly useful to mark functions
that are always failing and there should be a clear indication if they unexpectedly start to pass (for example
@@ -460,7 +468,7 @@ To use it, include in your top-most ``conftest.py`` file::
.. autoclass:: Testdir()
:members: runpytest,runpytest_subprocess,runpytest_inprocess,makeconftest,makepyfile
:members:
.. autoclass:: RunResult()
:members:
@@ -492,6 +500,32 @@ Each recorded warning is an instance of :class:`warnings.WarningMessage`.
differently; see :ref:`ensuring_function_triggers`.
tmp_path
~~~~~~~~
**Tutorial**: :doc:`tmpdir`
.. currentmodule:: _pytest.tmpdir
.. autofunction:: tmp_path()
:no-auto-options:
tmp_path_factory
~~~~~~~~~~~~~~~~
**Tutorial**: :ref:`tmp_path_factory example`
.. _`tmp_path_factory factory api`:
``tmp_path_factory`` instances have the following methods:
.. currentmodule:: _pytest.tmpdir
.. automethod:: TempPathFactory.mktemp
.. automethod:: TempPathFactory.getbasetemp
tmpdir
~~~~~~
@@ -551,6 +585,8 @@ Initialization hooks called for plugins and ``conftest.py`` files.
.. autofunction:: pytest_sessionstart
.. autofunction:: pytest_sessionfinish
.. autofunction:: pytest_plugin_registered
Test running hooks
~~~~~~~~~~~~~~~~~~
@@ -574,6 +610,8 @@ into interactive debugging when a test failure occurs.
The :py:mod:`_pytest.terminal` reported specifically uses
the reporting hook to print information about a test run.
.. autofunction:: pytest_pyfunc_call
Collection hooks
~~~~~~~~~~~~~~~~
@@ -583,6 +621,7 @@ Collection hooks
.. autofunction:: pytest_ignore_collect
.. autofunction:: pytest_collect_directory
.. autofunction:: pytest_collect_file
.. autofunction:: pytest_pycollect_makemodule
For influencing the collection of objects in Python modules
you can use the following hook:
@@ -596,12 +635,15 @@ items, delete or otherwise amend the test items:
.. autofunction:: pytest_collection_modifyitems
.. autofunction:: pytest_collection_finish
Reporting hooks
~~~~~~~~~~~~~~~
Session related reporting hooks:
.. autofunction:: pytest_collectstart
.. autofunction:: pytest_make_collect_report
.. autofunction:: pytest_itemcollected
.. autofunction:: pytest_collectreport
.. autofunction:: pytest_deselected
@@ -611,6 +653,7 @@ Session related reporting hooks:
.. autofunction:: pytest_terminal_summary
.. autofunction:: pytest_fixture_setup
.. autofunction:: pytest_fixture_post_finalizer
.. autofunction:: pytest_warning_captured
And here is the central hook for reporting about
test execution:
@@ -716,13 +759,6 @@ MarkGenerator
:members:
MarkInfo
~~~~~~~~
.. autoclass:: _pytest.mark.MarkInfo
:members:
Mark
~~~~
@@ -796,6 +832,33 @@ Special Variables
pytest treats some global variables in a special manner when defined in a test module.
collect_ignore
~~~~~~~~~~~~~~
**Tutorial**: :ref:`customizing-test-collection`
Can be declared in *conftest.py files* to exclude test directories or modules.
Needs to be ``list[str]``.
.. code-block:: python
collect_ignore = ["setup.py"]
collect_ignore_glob
~~~~~~~~~~~~~~~~~~~
**Tutorial**: :ref:`customizing-test-collection`
Can be declared in *conftest.py files* to exclude test directories or modules
with Unix shell-style wildcards. Needs to be ``list[str]`` where ``str`` can
contain glob patterns.
.. code-block:: python
collect_ignore_glob = ["*_ignore.py"]
pytest_plugins
~~~~~~~~~~~~~~
@@ -819,7 +882,7 @@ pytest_mark
**Tutorial**: :ref:`scoped-marking`
Can be declared at the **global** level in *test modules* to apply one or more :ref:`marks <marks ref>` to all
test functions and methods. Can be either a single mark or a sequence of marks.
test functions and methods. Can be either a single mark or a list of marks.
.. code-block:: python
@@ -832,7 +895,7 @@ test functions and methods. Can be either a single mark or a sequence of marks.
import pytest
pytestmark = (pytest.mark.integration, pytest.mark.slow)
pytestmark = [pytest.mark.integration, pytest.mark.slow]
PYTEST_DONT_REWRITE (module docstring)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -866,6 +929,11 @@ Contains comma-separated list of modules that should be loaded as plugins:
export PYTEST_PLUGINS=mymodule.plugin,xdist
PYTEST_DISABLE_PLUGIN_AUTOLOAD
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
When set, disables plugin auto-loading through setuptools entrypoints. Only explicitly specified plugins will be
loaded.
PYTEST_CURRENT_TEST
~~~~~~~~~~~~~~~~~~~
@@ -883,6 +951,12 @@ Here is a list of builtin configuration options that may be written in a ``pytes
file, usually located at the root of your repository. All options must be under a ``[pytest]`` section
(``[tool:pytest]`` for ``setup.cfg`` files).
.. warning::
Usage of ``setup.cfg`` is not recommended unless for very simple use cases. ``.cfg``
files use a different parser than ``pytest.ini`` and ``tox.ini`` which might cause hard to track
down problems.
When possible, it is recommended to use the latter files to hold your pytest configuration.
Configuration file options may be overwritten in the command-line by using ``-o/--override``, which can also be
passed multiple times. The expected format is ``name=value``. For example::
@@ -909,7 +983,7 @@ passed multiple times. The expected format is ``name=value``. For example::
.. confval:: cache_dir
.. versionadded:: 3.2
Sets a directory where stores content of cache plugin. Default directory is
``.pytest_cache`` which is created in :ref:`rootdir <rootdir>`. Directory may be
@@ -929,12 +1003,13 @@ passed multiple times. The expected format is ``name=value``. For example::
.. confval:: console_output_style
.. versionadded:: 3.3
Sets the console output style while running tests:
* ``classic``: classic pytest output.
* ``progress``: like classic pytest output, but with a progress indicator.
* ``count``: like progress, but shows progress as the number of tests completed instead of a percent.
The default is ``progress``, but you can fallback to ``classic`` if you prefer or
the new mode is causing unexpected problems:
@@ -948,7 +1023,7 @@ passed multiple times. The expected format is ``name=value``. For example::
.. confval:: doctest_encoding
.. versionadded:: 3.1
Default encoding to use to decode text files with docstrings.
:doc:`See how pytest handles doctests <doctest>`.
@@ -962,12 +1037,13 @@ passed multiple times. The expected format is ``name=value``. For example::
.. confval:: empty_parameter_set_mark
.. versionadded:: 3.4
Allows to pick the action for empty parametersets in parameterization
* ``skip`` skips tests with an empty parameterset (default)
* ``xfail`` marks tests with an empty parameterset as xfail(run=False)
* ``fail_at_collect`` raises an exception if parametrize collects an empty parameter set
.. code-block:: ini
@@ -984,7 +1060,7 @@ passed multiple times. The expected format is ``name=value``. For example::
.. confval:: filterwarnings
.. versionadded:: 3.1
Sets a list of filters and actions that should be taken for matched
warnings. By default all warnings emitted during the test session
@@ -1001,10 +1077,24 @@ passed multiple times. The expected format is ``name=value``. For example::
This tells pytest to ignore deprecation warnings and turn all other warnings
into errors. For more information please refer to :ref:`warnings`.
.. confval:: junit_family
.. versionadded:: 4.2
Configures the format of the generated JUnit XML file. The possible options are:
* ``xunit1`` (or ``legacy``): produces old style output, compatible with the xunit 1.0 format. **This is the default**.
* ``xunit2``: produces `xunit 2.0 style output <https://github.com/jenkinsci/xunit-plugin/blob/xunit-2.3.2/src/main/resources/org/jenkinsci/plugins/xunit/types/model/xsd/junit-10.xsd>`__,
which should be more compatible with latest Jenkins versions.
.. code-block:: ini
[pytest]
junit_family = xunit2
.. confval:: junit_suite_name
.. versionadded:: 3.1
To set the name of the root test suite xml item, you can configure the ``junit_suite_name`` option in your config file:
@@ -1016,7 +1106,7 @@ passed multiple times. The expected format is ``name=value``. For example::
.. confval:: log_cli_date_format
.. versionadded:: 3.3
Sets a :py:func:`time.strftime`-compatible string that will be used when formatting dates for live logging.
@@ -1029,7 +1119,7 @@ passed multiple times. The expected format is ``name=value``. For example::
.. confval:: log_cli_format
.. versionadded:: 3.3
Sets a :py:mod:`logging`-compatible string used to format live logging messages.
@@ -1043,7 +1133,7 @@ passed multiple times. The expected format is ``name=value``. For example::
.. confval:: log_cli_level
.. versionadded:: 3.3
Sets the minimum log message level that should be captured for live logging. The integer value or
the names of the levels can be used.
@@ -1058,7 +1148,7 @@ passed multiple times. The expected format is ``name=value``. For example::
.. confval:: log_date_format
.. versionadded:: 3.3
Sets a :py:func:`time.strftime`-compatible string that will be used when formatting dates for logging capture.
@@ -1072,7 +1162,7 @@ passed multiple times. The expected format is ``name=value``. For example::
.. confval:: log_file
.. versionadded:: 3.3
Sets a file name relative to the ``pytest.ini`` file where log messages should be written to, in addition
to the other logging facilities that are active.
@@ -1087,7 +1177,7 @@ passed multiple times. The expected format is ``name=value``. For example::
.. confval:: log_file_date_format
.. versionadded:: 3.3
Sets a :py:func:`time.strftime`-compatible string that will be used when formatting dates for the logging file.
@@ -1100,7 +1190,7 @@ passed multiple times. The expected format is ``name=value``. For example::
.. confval:: log_file_format
.. versionadded:: 3.3
Sets a :py:mod:`logging`-compatible string used to format logging messages redirected to the logging file.
@@ -1113,7 +1203,7 @@ passed multiple times. The expected format is ``name=value``. For example::
.. confval:: log_file_level
.. versionadded:: 3.3
Sets the minimum log message level that should be captured for the logging file. The integer value or
the names of the levels can be used.
@@ -1128,7 +1218,7 @@ passed multiple times. The expected format is ``name=value``. For example::
.. confval:: log_format
.. versionadded:: 3.3
Sets a :py:mod:`logging`-compatible string used to format captured logging messages.
@@ -1142,7 +1232,7 @@ passed multiple times. The expected format is ``name=value``. For example::
.. confval:: log_level
.. versionadded:: 3.3
Sets the minimum log message level that should be captured for logging capture. The integer value or
the names of the levels can be used.
@@ -1157,7 +1247,7 @@ passed multiple times. The expected format is ``name=value``. For example::
.. confval:: log_print
.. versionadded:: 3.3
If set to ``False``, will disable displaying captured logging messages for failed tests.
@@ -1171,8 +1261,11 @@ passed multiple times. The expected format is ``name=value``. For example::
.. confval:: markers
List of markers that are allowed in test functions, enforced when ``--strict`` command-line argument is used.
You can use a marker name per line, indented from the option name.
When the ``--strict`` command-line argument is used, only known markers -
defined in code by core pytest or some plugin - are allowed.
You can list additional markers in this setting to add them to the whitelist.
You can list one marker name per line, indented from the option name.
.. code-block:: ini
@@ -1229,7 +1322,8 @@ passed multiple times. The expected format is ``name=value``. For example::
.. confval:: python_classes
One or more name prefixes or glob-style patterns determining which classes
are considered for test collection. By default, pytest will consider any
are considered for test collection. Search for multiple glob patterns by
adding a space between patterns. By default, pytest will consider any
class prefixed with ``Test`` as a test collection. Here is an example of how
to collect tests from classes that end in ``Suite``:
@@ -1246,15 +1340,33 @@ passed multiple times. The expected format is ``name=value``. For example::
.. confval:: python_files
One or more Glob-style file patterns determining which python files
are considered as test modules. By default, pytest will consider
any file matching with ``test_*.py`` and ``*_test.py`` globs as a test
module.
are considered as test modules. Search for multiple glob patterns by
adding a space between patterns:
.. code-block:: ini
[pytest]
python_files = test_*.py check_*.py example_*.py
Or one per line:
.. code-block:: ini
[pytest]
python_files =
test_*.py
check_*.py
example_*.py
By default, files matching ``test_*.py`` and ``*_test.py`` will be considered
test modules.
.. confval:: python_functions
One or more name prefixes or glob-patterns determining which test functions
and methods are considered tests. By default, pytest will consider any
and methods are considered tests. Search for multiple glob patterns by
adding a space between patterns. By default, pytest will consider any
function prefixed with ``test`` as a test. Here is an example of how
to collect test functions and methods that end in ``_test``:
@@ -1272,7 +1384,7 @@ passed multiple times. The expected format is ``name=value``. For example::
.. confval:: testpaths
.. versionadded:: 2.8
Sets list of directories that should be searched for tests when
no specific directories, files or test ids are given in the command line when

View File

@@ -1,4 +1,4 @@
# pinning sphinx to 1.4.* due to search issues with rtd:
# https://github.com/rtfd/readthedocs-sphinx-ext/issues/25
sphinx ==1.4.*
pygments-pytest>=1.1.0
sphinx>=1.8.2,<2.1
sphinxcontrib-trio
sphinx-removed-in>=0.2.0

View File

@@ -22,7 +22,9 @@ it's an **xpass** and will be reported in the test summary.
``pytest`` counts and lists *skip* and *xfail* tests separately. Detailed
information about skipped/xfailed tests is not shown by default to avoid
cluttering the output. You can use the ``-r`` option to see details
corresponding to the "short" letters shown in the test progress::
corresponding to the "short" letters shown in the test progress:
.. code-block:: bash
pytest -rxXs # show extra info on xfailed, xpassed, and skipped tests
@@ -37,7 +39,7 @@ More details on the ``-r`` option can be found by running ``pytest -h``.
Skipping test functions
-----------------------
.. versionadded:: 2.9
The simplest way to skip a test function is to mark it with the ``skip`` decorator
which may be passed an optional ``reason``:
@@ -58,54 +60,68 @@ by calling the ``pytest.skip(reason)`` function:
if not valid_config():
pytest.skip("unsupported configuration")
The imperative method is useful when it is not possible to evaluate the skip condition
during import time.
It is also possible to skip the whole module using
``pytest.skip(reason, allow_module_level=True)`` at the module level:
.. code-block:: python
import sys
import pytest
if not pytest.config.getoption("--custom-flag"):
pytest.skip("--custom-flag is missing, skipping tests", allow_module_level=True)
if not sys.platform.startswith("win"):
pytest.skip("skipping windows-only tests", allow_module_level=True)
The imperative method is useful when it is not possible to evaluate the skip condition
during import time.
**Reference**: :ref:`pytest.mark.skip ref`
``skipif``
~~~~~~~~~~
.. versionadded:: 2.0
If you wish to skip something conditionally then you can use ``skipif`` instead.
Here is an example of marking a test function to be skipped
when run on an interpreter earlier than Python3.6 ::
when run on an interpreter earlier than Python3.6:
.. code-block:: python
import sys
@pytest.mark.skipif(sys.version_info < (3,6),
reason="requires python3.6 or higher")
@pytest.mark.skipif(sys.version_info < (3, 6), reason="requires python3.6 or higher")
def test_function():
...
If the condition evaluates to ``True`` during collection, the test function will be skipped,
with the specified reason appearing in the summary when using ``-rs``.
You can share ``skipif`` markers between modules. Consider this test module::
You can share ``skipif`` markers between modules. Consider this test module:
.. code-block:: python
# content of test_mymodule.py
import mymodule
minversion = pytest.mark.skipif(mymodule.__versioninfo__ < (1,1),
reason="at least mymodule-1.1 required")
minversion = pytest.mark.skipif(
mymodule.__versioninfo__ < (1, 1), reason="at least mymodule-1.1 required"
)
@minversion
def test_function():
...
You can import the marker and reuse it in another test module::
You can import the marker and reuse it in another test module:
.. code-block:: python
# test_myothermodule.py
from test_mymodule import minversion
@minversion
def test_anotherfunction():
...
@@ -124,24 +140,18 @@ so they are supported mainly for backward compatibility reasons.
Skip all test functions of a class or module
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
You can use the ``skipif`` marker (as any other marker) on classes::
You can use the ``skipif`` marker (as any other marker) on classes:
@pytest.mark.skipif(sys.platform == 'win32',
reason="does not run on windows")
.. code-block:: python
@pytest.mark.skipif(sys.platform == "win32", reason="does not run on windows")
class TestPosixCalls(object):
def test_function(self):
"will not be setup or run under 'win32' platform"
If the condition is ``True``, this marker will produce a skip result for
each of the test methods of that class.
.. warning::
The use of ``skipif`` on classes that use inheritance is strongly
discouraged. `A Known bug <https://github.com/pytest-dev/pytest/issues/568>`_
in pytest's markers may cause unexpected behavior in super classes.
If you want to skip all test functions of a module, you may use
the ``pytestmark`` name on the global level:
@@ -198,7 +208,7 @@ Here's a quick guide on how to skip tests in a module in different situations:
.. code-block:: python
pytestmark = pytest.mark.skipif(sys.platform == "win32", "tests for linux only")
pytestmark = pytest.mark.skipif(sys.platform == "win32", reason="tests for linux only")
3. Skip all tests in a module if some import is missing:
@@ -244,7 +254,7 @@ internally by raising a known exception.
``strict`` parameter
~~~~~~~~~~~~~~~~~~~~
.. versionadded:: 2.9
Both ``XFAIL`` and ``XPASS`` don't fail the test suite, unless the ``strict`` keyword-only
parameter is passed as ``True``:
@@ -271,10 +281,11 @@ You can change the default value of the ``strict`` parameter using the
~~~~~~~~~~~~~~~~~~~~
As with skipif_ you can also mark your expectation of a failure
on a particular platform::
on a particular platform:
@pytest.mark.xfail(sys.version_info >= (3,6),
reason="python3.6 api changes")
.. code-block:: python
@pytest.mark.xfail(sys.version_info >= (3, 6), reason="python3.6 api changes")
def test_function():
...
@@ -283,7 +294,7 @@ on a particular platform::
~~~~~~~~~~~~~~~~~~~~
If you want to be more specific as to why the test is failing, you can specify
a single exception, or a list of exceptions, in the ``raises`` argument.
a single exception, or a tuple of exceptions, in the ``raises`` argument.
.. code-block:: python
@@ -313,7 +324,9 @@ investigated later.
Ignoring xfail
~~~~~~~~~~~~~~
By specifying on the commandline::
By specifying on the commandline:
.. code-block:: bash
pytest --runxfail
@@ -327,12 +340,15 @@ Here is a simple test file with the several usages:
.. literalinclude:: example/xfail_demo.py
Running it with the report-on-xfail option gives this output::
Running it with the report-on-xfail option gives this output:
.. code-block:: pytest
example $ pytest -rx xfail_demo.py
=========================== test session starts ============================
platform linux -- Python 3.x.y, pytest-3.x.y, py-1.x.y, pluggy-0.x.y
rootdir: $REGENDOC_TMPDIR/example, inifile:
platform linux -- Python 3.x.y, pytest-4.x.y, py-1.x.y, pluggy-0.x.y
cachedir: $PYTHON_PREFIX/.pytest_cache
rootdir: $REGENDOC_TMPDIR/example
collected 7 items
xfail_demo.py xxxxxxx [100%]

Some files were not shown because too many files have changed in this diff Show More