Compare commits

...

146 Commits
3.0.4 ... 3.0.6

Author SHA1 Message Date
Ronny Pfannschmidt
0e64cd045c take off author_email after pypi rejects 2017-01-22 22:14:54 +01:00
Ronny Pfannschmidt
22da561ae5 fix copy+paste error, its supposed to be 3.0.6 2017-01-22 18:44:30 +01:00
Ronny Pfannschmidt
449b88c640 rerun regendoc with correct install 2017-01-22 18:44:30 +01:00
Ronny Pfannschmidt
34b898b47e generate the release announcement 2017-01-22 18:44:30 +01:00
Ronny Pfannschmidt
01eaf9db51 fix the xfail docstring typo at the actual docstring + regendoc 2017-01-22 18:44:30 +01:00
Ronny Pfannschmidt
4d0c635252 regendoc 2017-01-22 18:44:30 +01:00
Ronny Pfannschmidt
55f21bd2b9 bump version 2017-01-22 18:44:30 +01:00
Bruno Oliveira
c39d846c1b Merge pull request #2215 from RonnyPfannschmidt/fix-doctesting/devpi-bug
fix devpi test for doctesting env
2017-01-22 13:02:03 -02:00
Ronny Pfannschmidt
403122281a fix devpi test for doctesting env
due to a devpi bug, we always get a sdist install which in turn triggers
the pytest issue #2042 / #726

going for pyargs and a changed folder, it should no longer happen
(and will be tested firther after rebasing the release branch)
2017-01-22 11:48:05 +01:00
Bruno Oliveira
15a3b57ec7 Merge pull request #2120 from RonnyPfannschmidt/fix-2118
fix #2118 - rework Node._getcustomclass and Node compat properties
2017-01-20 14:38:55 -02:00
Ronny Pfannschmidt
6a96b464ab update changelog as suggested 2017-01-20 15:26:59 +01:00
Ronny Pfannschmidt
7b4afd8946 remove unused import 2017-01-20 12:09:49 +01:00
Ronny Pfannschmidt
1a2d6388ac Merge pull request #2211 from nicoddemus/trial-envs
Fix pytester internal plugin to work correctly with latest versions of zope.interface
2017-01-20 12:08:12 +01:00
Bruno Oliveira
3766060893 Merge branch 'master' into trial-envs 2017-01-20 08:37:34 -02:00
Ronny Pfannschmidt
4082f4024a comment out compatproperty deprecations
todo: reenable in the features branch
2017-01-20 11:25:48 +01:00
Ronny Pfannschmidt
e0c48b4fe7 Merge pull request #2212 from nicoddemus/pytester-rewrite
Assert statements of the pytester plugin again benefit from assertion rewriting

fixes #1920
2017-01-20 10:04:12 +01:00
Bruno Oliveira
7b4368f3f4 Merge pull request #2184 from eli-b/parseoutcomes-explicit-failure
Fail assert_outcomes() on missing terminal report
2017-01-19 21:38:54 -02:00
Bruno Oliveira
c477f09177 Assert statements of the pytester plugin again benefit from assertion rewriting
Fix #1920
2017-01-19 21:33:51 -02:00
Bruno Oliveira
2574da8d32 Fix pytester internal plugin to work correctly with latest versions of zope.interface
Fix #1989
2017-01-19 20:53:35 -02:00
Ronny Pfannschmidt
d15724f74f Merge pull request #2204 from nicoddemus/linux-marker-doc
Fix marker example on "linux" platform
2017-01-18 09:34:34 +01:00
Bruno Oliveira
61fa91f3d0 Fix marker example on "linux" platform
I cheated a little and updated the example output by hand. 😁

Fix #2200
2017-01-17 21:09:04 -02:00
Ronny Pfannschmidt
125e89b7f8 Merge pull request #2194 from rjprins/remove-reinterp-from-docs
Remove mention of --assert=reinterp in documentation
2017-01-14 14:58:50 +01:00
Rutger Prins
46a9861d29 Remove mention of --assert=reinterp in documentation
Related to #1940
2017-01-13 22:35:37 +01:00
Bruno Oliveira
3dfdbaf490 Merge pull request #2186 from nicoddemus/pytest-plugins-env-rewrite
Consider plugins loaded by PYTEST_PLUGINS for assertion rewrite
2017-01-12 23:29:58 -02:00
Bruno Oliveira
7cd7c283dd Refactor plugin specs handling into an isolated function 2017-01-12 14:31:35 -02:00
Bruno Oliveira
043aadeaf2 Consider plugins loaded by PYTEST_PLUGINS for assertion rewrite
Fix #2185
2017-01-11 17:15:16 -02:00
Eli Boyarski
e18b2a427a Fail assert_outcomes() on missing terminal report
Currently if the terminal report of testdir.runpytest() is missing,
assert_outcomes() on its output fails because parseoutcomes()
returns an unexpected value (None).
It's better to fail parseoutcomes() directly.
2017-01-11 17:09:37 +02:00
Ronny Pfannschmidt
ff309b3584 Merge pull request #2182 from pombredanne/patch-1
Ensure the LICENSE is included in built wheels
2017-01-10 21:44:43 +01:00
Philippe Ombredanne
aa82db9fe2 Ensure the LICENSE is included in built wheels
Otherwise it is not included by default as wheels do not honor the MANIFEST.in

Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
2017-01-10 19:25:57 +01:00
Bruno Oliveira
64cb67b703 Merge pull request #2174 from nicoddemus/appveyor-py36
Test py36 on AppVeyor
2017-01-05 22:35:20 -02:00
Bruno Oliveira
7559400183 Add py36 to test on AppVeyor
Fix #2134
2017-01-05 19:18:03 -02:00
Bruno Oliveira
9477f598d8 Merge pull request #2173 from jeffwidman/patch-1
Switch monkeypatch fixture to yield syntax
2017-01-04 23:17:30 -02:00
Jeff Widman
6d81c684cc Switch monkeypatch fixture to yield syntax 2017-01-04 15:06:52 -08:00
Bruno Oliveira
b769e41d8f Merge pull request #2170 from gogoengie/broken-links
Fix broken links
2017-01-02 21:57:17 -02:00
Peter Heatwole
ef903460b1 Fix broken links 2017-01-02 14:19:49 -08:00
Bruno Oliveira
78f03888f4 Merge pull request #2168 from jwilk/spelling
Fix typos
2017-01-01 20:08:08 -02:00
Jakub Wilk
03a7a2cd3e Fix typos 2016-12-31 19:01:15 +01:00
Bruno Oliveira
7592c5b491 Sort issues and user references in CHANGELOG 2016-12-27 23:20:34 -02:00
Bruno Oliveira
091148f843 Merge pull request #2136 from hroncok/i2132
Tests: Check for ModuleNotFoundError on Python 3.6+
2016-12-27 23:10:58 -02:00
Bruno Oliveira
718f0b0255 Merge pull request #2130 from malinoff/fix-2129
Use inspect to properly detect generators. Fixes #2129
2016-12-27 22:11:46 -02:00
Bruno Oliveira
b4295aa19e Merge pull request #2144 from sscherfke/patch-1
Explicitly add setuptools to install_requires
2016-12-27 22:08:39 -02:00
Bruno Oliveira
7d259401cd Merge pull request #2161 from nicoddemus/silence-trial-on-ci
Allow trial environments to fail on CI for now
2016-12-27 22:04:50 -02:00
Bruno Oliveira
515fb09995 Move module error compatibility code to _pytest.compat 2016-12-27 22:01:22 -02:00
Bruno Oliveira
088b742d40 Merge pull request #2149 from pelme/issue2148
Fix handling of ini configuration in subdirs when specifying ::
2016-12-27 21:54:14 -02:00
Miro Hrončok
6b24ce2a9d Test Python 3.6 on Travis CI
Partial fix for https://github.com/pytest-dev/pytest/issues/2134
2016-12-27 23:16:25 +01:00
Miro Hrončok
1680eeb3a3 Tests: Check for ModuleNotFoundError on Python 3.6+
Those tests originally checked for ImportError. Since Python 3.6
ModuleNotFoundError is raised in this context instead, the tests didn't work
as they are text based (so exception inheritance does not save the day).

Fixes https://github.com/pytest-dev/pytest/issues/2132
2016-12-27 23:15:12 +01:00
Andreas Pelme
0bb8a4a36d Fixed #2148 - parse directory names properly when args contains ::.
This commit also improves readbility in get_dirs_from_args by using self
documenting local functions.

get_dirs_from_args also now only returns directories that actually exists,
and not files to avoid confusion.

This commit also removes redundant checks in get_common_ancestor that
was already performed in get_dirs_from_args..
2016-12-27 15:28:56 +01:00
Bruno Oliveira
f7a1d369c3 Allow trial environments to fail on CI for now
While I agree this is *far* from ideal, IMHO It is better to ignore them for now otherwise we hamper contributors with unrelated errors.

We should fix this before the next release.

#1989
2016-12-26 21:47:50 -02:00
Bruno Oliveira
316406291d Merge pull request #2150 from lesteve/add-caught-warnings-info-when-warns-fail
Improve error message when pytest.warns fail
2016-12-26 21:42:15 -02:00
Bruno Oliveira
a27c824fd0 Merge pull request #2146 from lwm/minor-docs-fixup
Fix fixture/parametrize override example.
2016-12-26 20:13:00 -02:00
Bruno Oliveira
fc74eb332b Merge pull request #2128 from nicoddemus/pytest-m
Mention that Python also adds CWD to sys.path using python -m
2016-12-26 20:11:59 -02:00
Loïc Estève
bfada968d3 Update AUTHORS and CHANGELOG.rst
following contribution guidelines
2016-12-20 14:36:10 +01:00
Loïc Estève
c5f0b751f4 Improve error message when pytest.warns fail
The error message contains the expected type of warnings and the
warnings that were captured. Add tests.
2016-12-20 13:45:39 +01:00
Luke Murphy
f94189b48b Fix wrong fixture name. Closes #2143. 2016-12-20 01:48:32 +01:00
Stefan Scherfke
3f5edc705a Explicitly add setuptools to install_requires
Setuptools is used in `_pytest/config.py` but was not explicitly listed as requirement. This led to an error when creating a Conda package for pytest since setuptools is not necessarily installed by default in Conda envs.
2016-12-19 13:22:25 +01:00
Bruno Oliveira
caee5ce489 Avoid importing asyncio directly because that in turn initializes logging (#8) 2016-12-13 21:54:20 -02:00
Bruno Oliveira
1312b83866 Add CHANGELOG entry for #2129 2016-12-13 21:33:01 -02:00
Bruno Oliveira
45eb9b566c Move compat tests to a single file using testdir
This avoids having to resort to skipping modules in conftest.py file and avoids flake8 errors
2016-12-13 21:28:07 -02:00
Dmitry Malinovsky
3a59acf69f Use inspect to properly detect generators. Fixes #2129 2016-12-11 21:59:11 +06:00
Bruno Oliveira
81c9bdcd0b Mention that Python also adds CWD to sys.path using python -m 2016-12-10 16:55:04 -02:00
Bruno Oliveira
da40bcf97f Merge pull request #2119 from nicoddemus/changelog-dates
Add release dates to CHANGELOG entries
2016-12-08 19:49:22 -02:00
Bruno Oliveira
a4a30ae4a2 Merge pull request #2123 from oscarh/documentation-issue-687
Also update yield teardown for Issue #687
2016-12-07 12:46:43 -02:00
Oscar Hellström
f42a954cb3 Also update yield teardown for Issue #687 2016-12-07 15:08:38 +01:00
Ronny Pfannschmidt
9c285dfc1d fix #2118 - rework Node._getcustomclass and Node compat properties 2016-12-06 09:13:25 +01:00
Bruno Oliveira
8afca5d0fa Add release dates to CHANGELOG entry
Fix #721
2016-12-05 17:21:01 -02:00
Bruno Oliveira
3a0a1d2de3 Bump version to 3.0.6.dev0 2016-12-05 12:51:00 -02:00
Bruno Oliveira
6a52afc8c9 Merge pull request #2116 from nicoddemus/release-3.0.5
Release 3.0.5
2016-12-05 12:42:32 -02:00
Bruno Oliveira
f592c7746a Regendocs for 3.0.5 2016-12-05 07:22:06 -05:00
Bruno Oliveira
31f114e51f Add release announcement for 3.0.5 2016-12-05 10:19:27 -02:00
Bruno Oliveira
833acb9d3c Finalize CHANGELOG for 3.0.5 2016-12-05 10:07:37 -02:00
Bruno Oliveira
0febd855e1 Bump version to 3.0.5 2016-12-05 10:06:58 -02:00
Ronny Pfannschmidt
3c81f83602 Merge pull request #2113 from nicoddemus/approx-repr-unicode
Use a simple ``+-`` ASCII string in the string representation of pytest.approx In Python 2
2016-12-05 13:02:07 +01:00
Bruno Oliveira
57c4489916 Use a simple `+-` ASCII string in the string representation of pytest.approx In Python 2
Fix #2111
2016-12-02 20:01:53 -02:00
Bruno Oliveira
5365f7c9ca Merge pull request #2112 from ismail-s/patch-1
Fix minor typo
2016-12-02 14:12:06 -02:00
Ismail
1f0401ab62 Fix minor typo 2016-12-02 15:09:38 +00:00
Bruno Oliveira
7480342710 Fix typo in docstring of register_assert_rewrite 2016-12-02 09:22:47 -02:00
Bruno Oliveira
db62f160e1 Merge pull request #2073 from nicoddemus/fix-hookproxy-cache
Remove hook proxy cache
2016-12-02 09:07:20 -02:00
Bruno Oliveira
81528ea81f Remove hook proxy cache
Fix #2016
2016-12-02 07:32:11 -02:00
Ronny Pfannschmidt
64193add91 Merge pull request #2110 from nicoddemus/rewrite-warning-pytest-plugins
Fix false-positive assert rewrite warnings when using 'pytest_plugins'
2016-12-01 20:33:38 +01:00
Bruno Oliveira
bc0f7e6243 Fix false-positive assert rewrite warnings when using 'pytest_plugins'
pytest would emit false positive warnings about assertion-rewrite when a
module appears multiple times in plugins which depend
on other plugins using the 'pytest_plugins' mechanism
2016-12-01 15:50:08 -02:00
Ronny Pfannschmidt
9ed3d76b51 Merge pull request #2108 from lwm/exp-2105
Add warning for incorrect passing args to `-o`.
2016-12-01 13:49:24 +01:00
Luke Murphy
c856537e71 Add warning for incorrect passing args to -o. 2016-12-01 13:20:42 +01:00
Ronny Pfannschmidt
e612619aea Merge pull request #2106 from nicoddemus/sys-modules-none
Remove support code for earlier Python 3 version in Source.compile
2016-12-01 10:22:32 +01:00
Bruno Oliveira
30f0152ae6 Remove unused import 2016-11-30 22:34:02 -02:00
Bruno Oliveira
f8d195253e Remove support code for earlier Python 3 version in Source.compile
This code leaves None in sys.modules as a side effect but is no longer needed in the Python 3 versions we support.

Fix #2103
2016-11-30 22:23:02 -02:00
Bruno Oliveira
8208a77a3e Merge pull request #2098 from DuncanBetts/master
Improved description of functionality for Issue #687
2016-11-28 23:05:27 -02:00
Bruno Oliveira
8b4da9d955 Merge pull request #2100 from blueyed/fix-help-grammar
minor: fix grammar with help for --setup-{only,show}
2016-11-28 20:11:56 -02:00
Bruno Oliveira
454d288138 Merge pull request #2097 from lwm/junitxml-warn
Add `type` validation.
2016-11-28 20:10:51 -02:00
Daniel Hahler
40cffacadc minor: fix grammar with help for --setup-{only,show} 2016-11-28 21:33:15 +01:00
Duncan Betts
6473c3d87e Improved description of functionality for Issue #687 2016-11-28 14:30:25 +00:00
Luke Murphy
4e1609b12e Add type validation.
Argparse driven argument type validation is added for the
`--junit-xml` and `--confcutdir` arguments.

The commit partially reverts #2080. Closes #2089.
2016-11-28 02:16:01 +01:00
Bruno Oliveira
0735d4549d Merge pull request #2088 from nmundar/issue-2034
Issue 2034
2016-11-27 16:12:31 -02:00
Ronny Pfannschmidt
f25ba4dd0b Merge pull request #2095 from nicoddemus/readme-example
Use "inc" instead of "func" in the snipped on README
2016-11-27 19:11:35 +01:00
Bruno Oliveira
788e394c93 Use "inc" instead of "func" in the snipped on README and doc index
"inc" reads better, also fixed the line separators so
they have the same size
2016-11-27 15:49:39 -02:00
Bruno Oliveira
2d7197926a Improve CHANGELOG entry for #2034 2016-11-27 14:26:30 -02:00
nmundar
0a30f072e6 Show name argment in compatproperty deprecation message 2016-11-27 14:24:55 -02:00
nmundar
0e6ad8e59f update CHANGELOG and AUTHORS 2016-11-27 14:24:55 -02:00
nmundar
b38fad4b82 Add compatproperty deprecation warning. 2016-11-27 14:24:55 -02:00
Bruno Oliveira
483754216f Merge pull request #2094 from nicoddemus/remove-setuptools-pin
Remove setuptools pin now that upstream has been fixed
2016-11-27 14:15:47 -02:00
Bruno Oliveira
1e97ea60f7 Merge pull request #2091 from lwm/move-595-along
Add test case for #595.
2016-11-27 14:13:15 -02:00
Ronny Pfannschmidt
58f28bf049 Merge pull request #2093 from lwm/add-docs-notes
Add documentation building note.
2016-11-27 10:13:28 +01:00
Bruno Oliveira
5566b3ccb6 Remove setuptools pin now that upstream has been fixed
Related to pypa/setuptools#861
2016-11-27 03:30:23 -02:00
Bruno Oliveira
8138d88da2 Merge pull request #2087 from lwm/ref-recwarns
Add `:ref:` targets to `recwarn.rst`.
2016-11-26 18:06:17 -02:00
Luke Murphy
0aa891543d Add documentation building note. 2016-11-26 18:57:51 +01:00
Luke Murphy
6c5475660a Add test case for #595.
This new test proves that reports do not capture stdout
by default when skipped.
2016-11-26 18:49:24 +01:00
Luke Murphy
1aa5bfea11 Add :ref: targets to recwarn.rst. 2016-11-26 18:41:38 +01:00
Bruno Oliveira
a6084ed797 Merge pull request #2090 from avojnovicDk/issue-1808
Clarify test discovery docs.
2016-11-26 15:28:06 -02:00
Bruno Oliveira
d05d19da78 Merge pull request #2085 from DuncanBetts/master
Add hint of Issue #478 to error text
2016-11-26 15:25:54 -02:00
Bruno Oliveira
fa4d5da4ca Merge pull request #2092 from nicoddemus/pin-setuptools
Pin setuptools to < 29 because of AppVeyor failures
2016-11-26 15:25:43 -02:00
Bruno Oliveira
6120570198 Pin setuptools to < 29 because of AppVeyor failures
Related to pypa/setuptools#861

Remove the pin when we have a new setuptools release
2016-11-26 14:49:31 -02:00
Ana Vojnovic
2e6a58ab69 Clarify test discovery docs. 2016-11-26 15:21:39 +01:00
Duncan Betts
c1b83cdeea Add hint of Issue #478 to error text 2016-11-26 10:47:15 +00:00
Bruno Oliveira
33796c8a13 Merge pull request #2084 from nicoddemus/fix-coveralls-appveyor
Only execute "coveralls" toxenv once on AppVeyor
2016-11-24 19:43:52 -02:00
Bruno Oliveira
8763590eef Only execute "coveralls" toxenv on master once
Just noticed that the "coveralls" env was being execute after each env.

This was introduced by mistake in #2056
2016-11-24 19:27:27 -02:00
Ronny Pfannschmidt
b3efd9aa59 Merge pull request #2083 from nicoddemus/approx-check-float
Fix error in approx's repr with complex numbers
2016-11-24 19:40:29 +01:00
Bruno Oliveira
33c0b06fdf Fix error in approx's repr with complex numbers
Fix #2082
2016-11-24 15:33:12 -02:00
Bruno Oliveira
38f7562c7c Merge pull request #2080 from nicoddemus/confcutdir-check
Show an error if --confcutdir is not a valid directory
2016-11-23 10:23:01 -02:00
Bruno Oliveira
629d8e9fd6 Show an error if --confcutdir is not a valid directory
Fixes #2078
2016-11-23 09:49:11 -02:00
Ronny Pfannschmidt
a5b5090c72 Merge pull request #2070 from nedbat/bug2038
Don't fail if imp can't find the source for a .pyc file. #2038
2016-11-22 17:45:29 +01:00
Ronny Pfannschmidt
a3319ffe80 Merge pull request #2071 from nicoddemus/fix-flake8
Fix flake8 E305 and E306 errors
2016-11-22 13:22:11 +01:00
Bruno Oliveira
1e2b2af296 Merge pull request #2074 from nedbat/fix-double-spaces
Remove an accidental double space
2016-11-21 14:19:56 -02:00
Ned Batchelder
632c4d5daf Remove an accidental double space 2016-11-21 10:17:23 -05:00
Bruno Oliveira
984d4ce5ec Fix test_excinfo_getstatement that broke because of whitespace changes 2016-11-20 19:12:42 -02:00
Bruno Oliveira
1eb5a690d4 Fix flake8 E305 and E306 errors
These errors started to appear with flake8-3.1.1, while they don't appear with
version 3.1.0 (weird).
2016-11-20 18:59:15 -02:00
Ned Batchelder
06bb61bbe3 Don't fail if imp can't find the source for a .pyc file. #2038 2016-11-20 13:09:32 -05:00
Bruno Oliveira
cbf261c74e Merge pull request #2065 from sebastinas/spelling2
Fix spelling mistakes
2016-11-15 22:51:49 -02:00
Sebastian Ramacher
0ba930a11d Fix spelling mistakes
Signed-off-by: Sebastian Ramacher <sramacher@debian.org>
2016-11-15 23:05:58 +01:00
Bruno Oliveira
73d481552d Merge pull request #2058 from idlesign/patch-1
Docs: Added pytest promotional talk in Russian
2016-11-13 11:06:35 -02:00
Igor Starikov
50328f47db Docs: Added pytest promotional talk in Russian 2016-11-13 18:04:39 +07:00
Bruno Oliveira
f0e0250cd5 Merge pull request #2056 from nicoddemus/appveyor-list
Use one job for each tox env on AppVeyor
2016-11-12 22:15:41 -02:00
Bruno Oliveira
ec69514eb2 Only install pypy on AppVeyor for "pypy" tox-env 2016-11-12 20:20:59 -02:00
Bruno Oliveira
c169c883d3 Use one job for each tox env on AppVeyor
Some time ago when we first added support for testing pytest on AppVeyor,
jobs in a build would not start immediately one after the other, as if AppVeyor
would schedule jobs from other builds (projects) in its VMs. So it made sense
at the time to reduce the number of jobs.

I have noticed in other projects that this behavior has changed, and jobs
in a build now start one after the other. Having a separate list then improves
visibility when the build fails, because we can see at a glance the failing(s)
tox environment(s).
2016-11-12 12:49:12 -02:00
Bruno Oliveira
5185f2a6ae Merge pull request #2053 from nicoddemus/check-manifest-script
Use a wrapper script to bypass check-manifest if not under git
2016-11-12 12:12:54 -02:00
Bruno Oliveira
351395b7ea Use a wrapper script to bypass check-manifest if not under git
Related to comment in #2051
2016-11-12 11:39:41 -02:00
Ronny Pfannschmidt
71b68334e2 Merge pull request #2055 from nicoddemus/error-matrix-for-failing-jobs
Allow problematic jobs to fail instead of commenting them out
2016-11-11 22:38:33 +01:00
Bruno Oliveira
98caeedd9e Allow failure of pypy on AppVeyor
Related to #1963
2016-11-11 19:26:58 -02:00
Bruno Oliveira
1519b38af0 Allow failure of py35-trial on Travis
Related to #1989
2016-11-11 19:26:54 -02:00
Bruno Oliveira
3e01e83390 Bump version to 3.0.5.dev 2016-11-11 18:20:34 -02:00
Bruno Oliveira
ad4ef4f583 Merge pull request #2050 from nicoddemus/release-3.0.4
Release 3.0.4
2016-11-11 18:11:49 -02:00
Ronny Pfannschmidt
5717c71179 Merge pull request #2052 from nicoddemus/lint-readme
Check README.rst with rst-lint
2016-11-11 18:04:50 +01:00
Ronny Pfannschmidt
6c8c1da428 add pygments dependency because of rst-lint 2016-11-11 14:25:53 -02:00
Bruno Oliveira
b8c6f13b37 Check README.rst with rst-lint 2016-11-11 12:56:07 -02:00
Bruno Oliveira
8e0f7d3793 Merge pull request #2051 from nicoddemus/check-manifest
Check manifest
2016-11-10 22:58:48 -02:00
Bruno Oliveira
aaa547e763 Add some recursive-exclude related to hypothesis and freeze 2016-11-10 08:48:56 -02:00
Bruno Oliveira
26b1519534 Add keywords to setup.py as suggested by pyroma
Related to #1
2016-11-09 20:47:14 -02:00
Bruno Oliveira
84d7068723 Add "check-manifest" to linting and remove unused scripts from root
Fix #1
2016-11-09 20:42:28 -02:00
111 changed files with 1417 additions and 555 deletions

View File

@@ -22,13 +22,17 @@ env:
- TESTENV=py27-trial
- TESTENV=py35-pexpect
- TESTENV=py35-xdist
# Disable py35-trial temporarily: #1989
#- TESTENV=py35-trial
- TESTENV=py35-trial
- TESTENV=py27-nobyte
- TESTENV=doctesting
- TESTENV=freeze
- TESTENV=docs
matrix:
include:
- env: TESTENV=py36
python: '3.6-dev'
script: tox --recreate -e $TESTENV
notifications:

View File

@@ -44,6 +44,7 @@ David Mohr
David Vierra
Diego Russo
Dmitry Dygalo
Duncan Betts
Edison Gustavo Muenz
Edoardo Batini
Eduardo Schettino
@@ -70,6 +71,7 @@ Janne Vanhala
Jason R. Coombs
Javier Domingo Cansino
Javier Romero
Jeff Widman
John Towler
Jon Sonesen
Jordan Guymon
@@ -81,7 +83,9 @@ Katarzyna Jachim
Kevin Cox
Lee Kamentsky
Lev Maximov
Loic Esteve
Lukas Bednar
Luke Murphy
Maciek Fijalkowski
Maho
Marc Schlaich
@@ -101,6 +105,8 @@ Michael Birtwell
Michael Droettboom
Michael Seifert
Mike Lundy
Ned Batchelder
Neven Mundar
Nicolas Delaby
Oleg Pidsadnyi
Oliver Bestwalter
@@ -135,3 +141,4 @@ Tyler Goodlet
Vasily Kuznetsov
Wouter van Ackooy
Xuecong Liao
Eli Boyarski

View File

@@ -1,5 +1,120 @@
3.0.4
=====
3.0.6 (2017-01-29)
=======================
* pytest no longer generates ``PendingDeprecationWarning`` from its own operations, which was introduced by mistake in version ``3.0.5`` (`#2118`_).
Thanks to `@nicoddemus`_ for the report and `@RonnyPfannschmidt`_ for the PR.
* pytest no longer recognizes coroutine functions as yield tests (`#2129`_).
Thanks to `@malinoff`_ for the PR.
* Plugins loaded by the ``PYTEST_PLUGINS`` environment variable are now automatically
considered for assertion rewriting (`#2185`_).
Thanks `@nicoddemus`_ for the PR.
* Improve error message when pytest.warns fails (`#2150`_). The type(s) of the
expected warnings and the list of caught warnings is added to the
error message. Thanks `@lesteve`_ for the PR.
* Fix ``pytester`` internal plugin to work correctly with latest versions of
``zope.interface`` (`#1989`_). Thanks `@nicoddemus`_ for the PR.
* Assert statements of the ``pytester`` plugin again benefit from assertion rewriting (`#1920`_).
Thanks `@RonnyPfannschmidt`_ for the report and `@nicoddemus`_ for the PR.
* Specifying tests with colons like ``test_foo.py::test_bar`` for tests in
subdirectories with ini configuration files now uses the correct ini file
(`#2148`_). Thanks `@pelme`_.
* Fail ``testdir.runpytest().assert_outcomes()`` explicitly if the pytest
terminal output it relies on is missing. Thanks to `@eli-b`_ for the PR.
.. _@lesteve: https://github.com/lesteve
.. _@malinoff: https://github.com/malinoff
.. _@pelme: https://github.com/pelme
.. _@eli-b: https://github.com/eli-b
.. _#2118: https://github.com/pytest-dev/pytest/issues/2118
.. _#1989: https://github.com/pytest-dev/pytest/issues/1989
.. _#1920: https://github.com/pytest-dev/pytest/issues/1920
.. _#2129: https://github.com/pytest-dev/pytest/issues/2129
.. _#2148: https://github.com/pytest-dev/pytest/issues/2148
.. _#2150: https://github.com/pytest-dev/pytest/issues/2150
.. _#2185: https://github.com/pytest-dev/pytest/issues/2185
3.0.5 (2016-12-05)
==================
* Add warning when not passing ``option=value`` correctly to ``-o/--override-ini`` (`#2105`_).
Also improved the help documentation. Thanks to `@mbukatov`_ for the report and
`@lwm`_ for the PR.
* Now ``--confcutdir`` and ``--junit-xml`` are properly validated if they are directories
and filenames, respectively (`#2089`_ and `#2078`_). Thanks to `@lwm`_ for the PR.
* Add hint to error message hinting possible missing ``__init__.py`` (`#478`_). Thanks `@DuncanBetts`_.
* More accurately describe when fixture finalization occurs in documentation (`#687`_). Thanks `@DuncanBetts`_.
* Provide ``:ref:`` targets for ``recwarn.rst`` so we can use intersphinx referencing.
Thanks to `@dupuy`_ for the report and `@lwm`_ for the PR.
* In Python 2, use a simple ``+-`` ASCII string in the string representation of ``pytest.approx`` (for example ``"4 +- 4.0e-06"``)
because it is brittle to handle that in different contexts and representations internally in pytest
which can result in bugs such as `#2111`_. In Python 3, the representation still uses ``±`` (for example ``4 ± 4.0e-06``).
Thanks `@kerrick-lyft`_ for the report and `@nicoddemus`_ for the PR.
* Using ``item.Function``, ``item.Module``, etc., is now issuing deprecation warnings, prefer
``pytest.Function``, ``pytest.Module``, etc., instead (`#2034`_).
Thanks `@nmundar`_ for the PR.
* Fix error message using ``approx`` with complex numbers (`#2082`_).
Thanks `@adler-j`_ for the report and `@nicoddemus`_ for the PR.
* Fixed false-positives warnings from assertion rewrite hook for modules imported more than
once by the ``pytest_plugins`` mechanism.
Thanks `@nicoddemus`_ for the PR.
* Remove an internal cache which could cause hooks from ``conftest.py`` files in
sub-directories to be called in other directories incorrectly (`#2016`_).
Thanks `@d-b-w`_ for the report and `@nicoddemus`_ for the PR.
* Remove internal code meant to support earlier Python 3 versions that produced the side effect
of leaving ``None`` in ``sys.modules`` when expressions were evaluated by pytest (for example passing a condition
as a string to ``pytest.mark.skipif``)(`#2103`_).
Thanks `@jaraco`_ for the report and `@nicoddemus`_ for the PR.
* Cope gracefully with a .pyc file with no matching .py file (`#2038`_). Thanks
`@nedbat`_.
.. _@adler-j: https://github.com/adler-j
.. _@d-b-w: https://bitbucket.org/d-b-w/
.. _@DuncanBetts: https://github.com/DuncanBetts
.. _@dupuy: https://bitbucket.org/dupuy/
.. _@kerrick-lyft: https://github.com/kerrick-lyft
.. _@lwm: https://github.com/lwm
.. _@mbukatov: https://github.com/mbukatov
.. _@nedbat: https://github.com/nedbat
.. _@nmundar: https://github.com/nmundar
.. _#2016: https://github.com/pytest-dev/pytest/issues/2016
.. _#2034: https://github.com/pytest-dev/pytest/issues/2034
.. _#2038: https://github.com/pytest-dev/pytest/issues/2038
.. _#2078: https://github.com/pytest-dev/pytest/issues/2078
.. _#2082: https://github.com/pytest-dev/pytest/issues/2082
.. _#2089: https://github.com/pytest-dev/pytest/issues/2089
.. _#2103: https://github.com/pytest-dev/pytest/issues/2103
.. _#2105: https://github.com/pytest-dev/pytest/issues/2105
.. _#2111: https://github.com/pytest-dev/pytest/issues/2111
.. _#478: https://github.com/pytest-dev/pytest/issues/478
.. _#687: https://github.com/pytest-dev/pytest/issues/687
3.0.4 (2016-11-09)
==================
* Import errors when collecting test modules now display the full traceback (`#1976`_).
Thanks `@cwitty`_ for the report and `@nicoddemus`_ for the PR.
@@ -22,10 +137,10 @@
Thanks `@RonnyPfannschmidt`_ for the report and `@nicoddemus`_ for the PR.
* Report teardown output on test failure (`#442`_).
Thanks `@matclab`_ or the PR.
Thanks `@matclab`_ for the PR.
* Fix teardown error message in generated xUnit XML.
Thanks `@gdyuldin`_ or the PR.
Thanks `@gdyuldin`_ for the PR.
* Properly handle exceptions in ``multiprocessing`` tasks (`#1984`_).
Thanks `@adborden`_ for the report and `@nicoddemus`_ for the PR.
@@ -52,8 +167,8 @@
.. _#1649: https://github.com/pytest-dev/pytest/issues/1649
3.0.3
=====
3.0.3 (2016-09-28)
==================
* The ``ids`` argument to ``parametrize`` again accepts ``unicode`` strings
in Python 2 (`#1905`_).
@@ -91,8 +206,8 @@
3.0.2
=====
3.0.2 (2016-09-01)
==================
* Improve error message when passing non-string ids to ``pytest.mark.parametrize`` (`#1857`_).
Thanks `@okken`_ for the report and `@nicoddemus`_ for the PR.
@@ -131,8 +246,8 @@
.. _#1898: https://github.com/pytest-dev/pytest/issues/1898
3.0.1
=====
3.0.1 (2016-08-23)
==================
* Fix regression when ``importorskip`` is used at module level (`#1822`_).
Thanks `@jaraco`_ and `@The-Compiler`_ for the report and `@nicoddemus`_ for the PR.
@@ -157,8 +272,8 @@
.. _#1849: https://github.com/pytest-dev/pytest/issues/1849
3.0.0
=====
3.0.0 (2016-08-18)
==================
**Incompatible changes**
@@ -583,8 +698,8 @@ time or change existing behaviors in order to make them less surprising/more use
.. _@matthiasha: https://github.com/matthiasha
2.9.2
=====
2.9.2 (2016-05-31)
==================
**Bug Fixes**
@@ -595,7 +710,7 @@ time or change existing behaviors in order to make them less surprising/more use
Thanks `@astraw38`_ for reporting the issue (`#1496`_) and `@tomviner`_
for PR the (`#1524`_).
* Fix win32 path issue when puttinging custom config file with absolute path
* Fix win32 path issue when putting custom config file with absolute path
in ``pytest.main("-c your_absolute_path")``.
* Fix maximum recursion depth detection when raised error class is not aware
@@ -622,8 +737,8 @@ time or change existing behaviors in order to make them less surprising/more use
.. _@astraw38: https://github.com/astraw38
2.9.1
=====
2.9.1 (2016-03-17)
==================
**Bug Fixes**
@@ -658,8 +773,8 @@ time or change existing behaviors in order to make them less surprising/more use
.. _@asottile: https://github.com/asottile
2.9.0
=====
2.9.0 (2016-02-29)
==================
**New Features**
@@ -779,13 +894,13 @@ time or change existing behaviors in order to make them less surprising/more use
.. _@pquentin: https://github.com/pquentin
.. _@ioggstream: https://github.com/ioggstream
2.8.7
=====
2.8.7 (2016-01-24)
==================
- fix #1338: use predictable object resolution for monkeypatch
2.8.6
=====
2.8.6 (2016-01-21)
==================
- fix #1259: allow for double nodeids in junitxml,
this was a regression failing plugins combinations
@@ -816,8 +931,8 @@ time or change existing behaviors in order to make them less surprising/more use
Thanks Georgy Dyuldin for the PR.
2.8.5
=====
2.8.5 (2015-12-11)
==================
- fix #1243: fixed issue where class attributes injected during collection could break pytest.
PR by Alexei Kozlenok, thanks Ronny Pfannschmidt and Bruno Oliveira for the review and help.
@@ -830,8 +945,8 @@ time or change existing behaviors in order to make them less surprising/more use
Bruno Oliveira for the PR.
2.8.4
=====
2.8.4 (2015-12-06)
==================
- fix #1190: ``deprecated_call()`` now works when the deprecated
function has been already called by another test in the same
@@ -854,8 +969,8 @@ time or change existing behaviors in order to make them less surprising/more use
- a number of documentation modernizations wrt good practices.
Thanks Bruno Oliveira for the PR.
2.8.3
=====
2.8.3 (2015-11-18)
==================
- fix #1169: add __name__ attribute to testcases in TestCaseFunction to
support the @unittest.skip decorator on functions and methods.
@@ -882,8 +997,8 @@ time or change existing behaviors in order to make them less surprising/more use
system integrity protection (thanks Florian)
2.8.2
=====
2.8.2 (2015-10-07)
==================
- fix #1085: proper handling of encoding errors when passing encoded byte
strings to pytest.parametrize in Python 2.
@@ -902,8 +1017,8 @@ time or change existing behaviors in order to make them less surprising/more use
Thanks Sergey B Kirpichev and Vital Kudzelka for contributing and Bruno
Oliveira for the PR.
2.8.1
=====
2.8.1 (2015-09-29)
==================
- fix #1034: Add missing nodeid on pytest_logwarning call in
addhook. Thanks Simon Gomizelj for the PR.
@@ -927,7 +1042,7 @@ time or change existing behaviors in order to make them less surprising/more use
- (experimental) adapt more SEMVER style versioning and change meaning of
master branch in git repo: "master" branch now keeps the bugfixes, changes
aimed for micro releases. "features" branch will only be be released
aimed for micro releases. "features" branch will only be released
with minor or major pytest releases.
- Fix issue #766 by removing documentation references to distutils.
@@ -949,8 +1064,8 @@ time or change existing behaviors in order to make them less surprising/more use
- fix issue 1029: transform errors when writing cache values into pytest-warnings
2.8.0
=====
2.8.0 (2015-09-18)
==================
- new ``--lf`` and ``-ff`` options to run only the last failing tests or
"failing tests first" from the last run. This functionality is provided
@@ -1061,7 +1176,7 @@ time or change existing behaviors in order to make them less surprising/more use
- new option ``--import-mode`` to allow to change test module importing
behaviour to append to sys.path instead of prepending. This better allows
to run test modules against installated versions of a package even if the
to run test modules against installed versions of a package even if the
package under test has the same import root. In this example::
testing/__init__.py
@@ -1139,8 +1254,8 @@ time or change existing behaviors in order to make them less surprising/more use
properly used to discover ``rootdir`` and ``ini`` files.
Thanks Peter Lauri for the report and Bruno Oliveira for the PR.
2.7.3 (compared to 2.7.2)
=============================
2.7.3 (2015-09-15)
==================
- Allow 'dev', 'rc', or other non-integer version strings in ``importorskip``.
Thanks to Eric Hunsberger for the PR.
@@ -1182,8 +1297,8 @@ time or change existing behaviors in order to make them less surprising/more use
directories created by this fixture (defaults to $TEMP/pytest-$USER).
Thanks Bruno Oliveira for the PR.
2.7.2 (compared to 2.7.1)
=============================
2.7.2 (2015-06-23)
==================
- fix issue767: pytest.raises value attribute does not contain the exception
instance on Python 2.6. Thanks Eric Siegerman for providing the test
@@ -1211,15 +1326,15 @@ time or change existing behaviors in order to make them less surprising/more use
which has a refined algorithm for traceback generation.
2.7.1 (compared to 2.7.0)
=============================
2.7.1 (2015-05-19)
==================
- fix issue731: do not get confused by the braces which may be present
and unbalanced in an object's repr while collapsing False
explanations. Thanks Carl Meyer for the report and test case.
- fix issue553: properly handling inspect.getsourcelines failures in
FixtureLookupError which would lead to to an internal error,
FixtureLookupError which would lead to an internal error,
obfuscating the original problem. Thanks talljosh for initial
diagnose/patch and Bruno Oliveira for final patch.
@@ -1244,8 +1359,8 @@ time or change existing behaviors in order to make them less surprising/more use
- reintroduced _pytest fixture of the pytester plugin which is used
at least by pytest-xdist.
2.7.0 (compared to 2.6.4)
=============================
2.7.0 (2015-03-26)
==================
- fix issue435: make reload() work when assert rewriting is active.
Thanks Daniel Hahler.
@@ -1314,8 +1429,8 @@ time or change existing behaviors in order to make them less surprising/more use
``sys.last_traceback`` are set, so that a user can inspect the error
via postmortem debugging (almarklein).
2.6.4
=====
2.6.4 (2014-10-24)
==================
- Improve assertion failure reporting on iterables, by using ndiff and
pprint.
@@ -1343,8 +1458,8 @@ time or change existing behaviors in order to make them less surprising/more use
- fix issue614: fixed pastebin support.
2.6.3
=====
2.6.3 (2014-09-24)
==================
- fix issue575: xunit-xml was reporting collection errors as failures
instead of errors, thanks Oleg Sinyavskiy.
@@ -1362,7 +1477,7 @@ time or change existing behaviors in order to make them less surprising/more use
- fix conftest related fixture visibility issue: when running with a
CWD outside of a test package pytest would get fixture discovery wrong.
Thanks to Wolfgang Schnerring for figuring out a reproducable example.
Thanks to Wolfgang Schnerring for figuring out a reproducible example.
- Introduce pytest_enter_pdb hook (needed e.g. by pytest_timeout to cancel the
timeout when interactively entering pdb). Thanks Wolfgang Schnerring.
@@ -1370,8 +1485,8 @@ time or change existing behaviors in order to make them less surprising/more use
- check xfail/skip also with non-python function test items. Thanks
Floris Bruynooghe.
2.6.2
=====
2.6.2 (2014-09-05)
==================
- Added function pytest.freeze_includes(), which makes it easy to embed
pytest into executables using tools like cx_freeze.
@@ -1399,8 +1514,8 @@ time or change existing behaviors in order to make them less surprising/more use
replace the py.test introspection message but are shown in addition
to them.
2.6.1
=====
2.6.1 (2014-08-07)
==================
- No longer show line numbers in the --verbose output, the output is now
purely the nodeid. The line number is still shown in failure reports.
@@ -1536,8 +1651,8 @@ time or change existing behaviors in order to make them less surprising/more use
in monkeypatch plugin. Improves output in documentation.
2.5.2
=====
2.5.2 (2014-01-29)
==================
- fix issue409 -- better interoperate with cx_freeze by not
trying to import from collections.abc which causes problems
@@ -1561,11 +1676,11 @@ time or change existing behaviors in order to make them less surprising/more use
- fix issue429: comparing byte strings with non-ascii chars in assert
expressions now work better. Thanks Floris Bruynooghe.
- make capfd/capsys.capture private, its unused and shouldnt be exposed
- make capfd/capsys.capture private, its unused and shouldn't be exposed
2.5.1
=====
2.5.1 (2013-12-17)
==================
- merge new documentation styling PR from Tobias Bieniek.
@@ -1585,8 +1700,8 @@ time or change existing behaviors in order to make them less surprising/more use
2.5.0
=====
2.5.0 (2013-12-12)
==================
- dropped python2.5 from automated release testing of pytest itself
which means it's probably going to break soon (but still works
@@ -1618,7 +1733,7 @@ time or change existing behaviors in order to make them less surprising/more use
to problems for more than >966 non-function scoped parameters).
- fix issue290 - there is preliminary support now for parametrizing
with repeated same values (sometimes useful to to test if calling
with repeated same values (sometimes useful to test if calling
a second time works as with the first time).
- close issue240 - document precisely how pytest module importing
@@ -1721,8 +1836,8 @@ time or change existing behaviors in order to make them less surprising/more use
- fix verbose reporting for @mock'd test functions
2.4.2
=====
2.4.2 (2013-10-04)
==================
- on Windows require colorama and a newer py lib so that py.io.TerminalWriter()
now uses colorama instead of its own ctypes hacks. (fixes issue365)
@@ -1752,8 +1867,8 @@ time or change existing behaviors in order to make them less surprising/more use
- add pluginmanager.do_configure(config) as a link to
config.do_configure() for plugin-compatibility
2.4.1
=====
2.4.1 (2013-10-02)
==================
- When using parser.addoption() unicode arguments to the
"type" keyword should also be converted to the respective types.
@@ -1832,7 +1947,7 @@ new features:
- fix issue322: tearDownClass is not run if setUpClass failed. Thanks
Mathieu Agopian for the initial fix. Also make all of pytest/nose
finalizer mimick the same generic behaviour: if a setupX exists and
finalizer mimic the same generic behaviour: if a setupX exists and
fails, don't run teardownX. This internally introduces a new method
"node.addfinalizer()" helper which can only be called during the setup
phase of a node.
@@ -1937,8 +2052,8 @@ Bug fixes:
".section(title)" and ".line(msg)" methods to print extra
information at the end of a test run.
2.3.5
=====
2.3.5 (2013-04-30)
==================
- fix issue169: respect --tb=style with setup/teardown errors as well.
@@ -1951,11 +2066,11 @@ Bug fixes:
(thanks Adam Goucher)
- Issue 265 - integrate nose setup/teardown with setupstate
so it doesnt try to teardown if it did not setup
so it doesn't try to teardown if it did not setup
- issue 271 - dont write junitxml on slave nodes
- issue 271 - don't write junitxml on slave nodes
- Issue 274 - dont try to show full doctest example
- Issue 274 - don't try to show full doctest example
when doctest does not know the example location
- issue 280 - disable assertion rewriting on buggy CPython 2.6.0
@@ -1991,7 +2106,7 @@ Bug fixes:
- allow to specify prefixes starting with "_" when
customizing python_functions test discovery. (thanks Graham Horler)
- improve PYTEST_DEBUG tracing output by puting
- improve PYTEST_DEBUG tracing output by putting
extra data on a new lines with additional indent
- ensure OutcomeExceptions like skip/fail have initialized exception attributes
@@ -2002,8 +2117,8 @@ Bug fixes:
- fix issue266 - accept unicode in MarkEvaluator expressions
2.3.4
=====
2.3.4 (2012-11-20)
==================
- yielded test functions will now have autouse-fixtures active but
cannot accept fixtures as funcargs - it's anyway recommended to
@@ -2022,8 +2137,8 @@ Bug fixes:
need to write as -k "TestClass and test_method" to match a certain
method in a certain test class.
2.3.3
=====
2.3.3 (2012-11-06)
==================
- fix issue214 - parse modules that contain special objects like e. g.
flask's request object which blows up on getattr access if no request
@@ -2040,7 +2155,7 @@ Bug fixes:
- fix issue209 - reintroduce python2.4 support by depending on newer
pylib which re-introduced statement-finding for pre-AST interpreters
- nose support: only call setup if its a callable, thanks Andrew
- nose support: only call setup if it's a callable, thanks Andrew
Taumoefolau
- fix issue219 - add py2.4-3.3 classifiers to TROVE list
@@ -2054,8 +2169,8 @@ Bug fixes:
- fix issue127 - improve documentation for pytest_addoption() and
add a ``config.getoption(name)`` helper function for consistency.
2.3.2
=====
2.3.2 (2012-10-25)
==================
- fix issue208 and fix issue29 use new py version to avoid long pauses
when printing tracebacks in long modules
@@ -2087,8 +2202,8 @@ Bug fixes:
- add tox.ini to pytest distribution so that ignore-dirs and others config
bits are properly distributed for maintainers who run pytest-own tests
2.3.1
=====
2.3.1 (2012-10-20)
==================
- fix issue202 - fix regression: using "self" from fixture functions now
works as expected (it's the same "self" instance that a test method
@@ -2100,8 +2215,8 @@ Bug fixes:
- link to web pages from --markers output which provides help for
pytest.mark.* usage.
2.3.0
=====
2.3.0 (2012-10-19)
==================
- fix issue202 - better automatic names for parametrized test functions
- fix issue139 - introduce @pytest.fixture which allows direct scoping
@@ -2136,7 +2251,7 @@ Bug fixes:
- fix issue128: show captured output when capsys/capfd are used
- fix issue179: propperly show the dependency chain of factories
- fix issue179: properly show the dependency chain of factories
- pluginmanager.register(...) now raises ValueError if the
plugin has been already registered or the name is taken
@@ -2177,10 +2292,10 @@ Bug fixes:
- don't show deselected reason line if there is none
- py.test -vv will show all of assert comparisations instead of truncating
- py.test -vv will show all of assert comparisons instead of truncating
2.2.4
=====
2.2.4 (2012-05-22)
==================
- fix error message for rewritten assertions involving the % operator
- fix issue 126: correctly match all invalid xml characters for junitxml
@@ -2188,7 +2303,7 @@ Bug fixes:
- fix issue with unittest: now @unittest.expectedFailure markers should
be processed correctly (you can also use @pytest.mark markers)
- document integration with the extended distribute/setuptools test commands
- fix issue 140: propperly get the real functions
- fix issue 140: properly get the real functions
of bound classmethods for setup/teardown_class
- fix issue #141: switch from the deceased paste.pocoo.org to bpaste.net
- fix issue #143: call unconfigure/sessionfinish always when
@@ -2196,13 +2311,13 @@ Bug fixes:
- fix issue #144: better mangle test ids to junitxml classnames
- upgrade distribute_setup.py to 0.6.27
2.2.3
=====
2.2.3 (2012-02-05)
==================
- fix uploaded package to only include neccesary files
- fix uploaded package to only include necessary files
2.2.2
=====
2.2.2 (2012-02-05)
==================
- fix issue101: wrong args to unittest.TestCase test function now
produce better output
@@ -2221,8 +2336,8 @@ Bug fixes:
- allow adding of attributes to test reports such that it also works
with distributed testing (no upgrade of pytest-xdist needed)
2.2.1
=====
2.2.1 (2011-12-16)
==================
- fix issue99 (in pytest and py) internallerrors with resultlog now
produce better output - fixed by normalizing pytest_internalerror
@@ -2238,8 +2353,8 @@ Bug fixes:
- fix collection crash due to unknown-source collected items, thanks
to Ralf Schmitt (fixed by depending on a more recent pylib)
2.2.0
=====
2.2.0 (2011-11-18)
==================
- fix issue90: introduce eager tearing down of test items so that
teardown function are called earlier.
@@ -2273,8 +2388,8 @@ Bug fixes:
- simplify junitxml output code by relying on py.xml
- add support for skip properties on unittest classes and functions
2.1.3
=====
2.1.3 (2011-10-18)
==================
- fix issue79: assertion rewriting failed on some comparisons in boolops
- correctly handle zero length arguments (a la pytest '')
@@ -2282,8 +2397,8 @@ Bug fixes:
- fix issue75 / skipping test failure on jython
- fix issue77 / Allow assertrepr_compare hook to apply to a subset of tests
2.1.2
=====
2.1.2 (2011-09-24)
==================
- fix assertion rewriting on files with windows newlines on some Python versions
- refine test discovery by package/module name (--pyargs), thanks Florian Mayer
@@ -2305,8 +2420,8 @@ Bug fixes:
- fix issue61: assertion rewriting on boolean operations with 3 or more operands
- you can now build a man page with "cd doc ; make man"
2.1.0
=====
2.1.0 (2011-07-09)
==================
- fix issue53 call nosestyle setup functions with correct ordering
- fix issue58 and issue59: new assertion code fixes
@@ -2325,8 +2440,8 @@ Bug fixes:
- report KeyboardInterrupt even if interrupted during session startup
- fix issue 35 - provide PDF doc version and download link from index page
2.0.3
=====
2.0.3 (2011-05-11)
==================
- fix issue38: nicer tracebacks on calls to hooks, particularly early
configure/sessionstart ones
@@ -2340,13 +2455,13 @@ Bug fixes:
- don't require zlib (and other libs) for genscript plugin without
--genscript actually being used.
- speed up skips (by not doing a full traceback represenation
- speed up skips (by not doing a full traceback representation
internally)
- fix issue37: avoid invalid characters in junitxml's output
2.0.2
=====
2.0.2 (2011-03-09)
==================
- tackle issue32 - speed up test runs of very quick test functions
by reducing the relative overhead
@@ -2388,17 +2503,17 @@ Bug fixes:
this.
- fixed typos in the docs (thanks Victor Garcia, Brianna Laugher) and particular
thanks to Laura Creighton who also revieved parts of the documentation.
thanks to Laura Creighton who also reviewed parts of the documentation.
- fix slighly wrong output of verbose progress reporting for classes
- fix slightly wrong output of verbose progress reporting for classes
(thanks Amaury)
- more precise (avoiding of) deprecation warnings for node.Class|Function accesses
- avoid std unittest assertion helper code in tracebacks (thanks Ronny)
2.0.1
=====
2.0.1 (2011-02-07)
==================
- refine and unify initial capturing so that it works nicely
even if the logging module is used on an early-loaded conftest.py
@@ -2446,12 +2561,12 @@ Bug fixes:
parametraization remains the "pytest_generate_tests"
mechanism, see the docs.
2.0.0
=====
2.0.0 (2010-11-25)
==================
- pytest-2.0 is now its own package and depends on pylib-2.0
- new ability: python -m pytest / python -m pytest.main ability
- new python invcation: pytest.main(args, plugins) to load
- new python invocation: pytest.main(args, plugins) to load
some custom plugins early.
- try harder to run unittest test suites in a more compatible manner
by deferring setup/teardown semantics to the unittest package.
@@ -2491,8 +2606,8 @@ Bug fixes:
- add ability to use "class" level for cached_setup helper
- fix strangeness: mark.* objects are now immutable, create new instances
1.3.4
=====
1.3.4 (2010-09-14)
==================
- fix issue111: improve install documentation for windows
- fix issue119: fix custom collectability of __init__.py as a module
@@ -2500,8 +2615,8 @@ Bug fixes:
- fix issue115: unify internal exception passthrough/catching/GeneratorExit
- fix issue118: new --tb=native for presenting cpython-standard exceptions
1.3.3
=====
1.3.3 (2010-07-30)
==================
- fix issue113: assertion representation problem with triple-quoted strings
(and possibly other cases)
@@ -2515,8 +2630,8 @@ Bug fixes:
(thanks Armin Ronacher for reporting)
- remove trailing whitespace in all py/text distribution files
1.3.2
=====
1.3.2 (2010-07-08)
==================
**New features**
@@ -2588,8 +2703,8 @@ Bug fixes:
- fix homedir detection on Windows
- ship distribute_setup.py version 0.6.13
1.3.1
=====
1.3.1 (2010-05-25)
==================
**New features**
@@ -2658,8 +2773,8 @@ Bug fixes:
(and internally be more careful when presenting unexpected byte sequences)
1.3.0
=====
1.3.0 (2010-05-05)
==================
- deprecate --report option in favour of a new shorter and easier to
remember -r option: it takes a string argument consisting of any
@@ -2690,7 +2805,7 @@ Bug fixes:
- extend and refine xfail mechanism:
``@py.test.mark.xfail(run=False)`` do not run the decorated test
``@py.test.mark.xfail(reason="...")`` prints the reason string in xfail summaries
specifiying ``--runxfail`` on command line virtually ignores xfail markers
specifying ``--runxfail`` on command line virtually ignores xfail markers
- expose (previously internal) commonly useful methods:
py.io.get_terminal_with() -> return terminal width
@@ -2723,8 +2838,8 @@ Bug fixes:
- added links to the new capturelog and coverage plugins
1.2.0
=====
1.2.0 (2010-01-18)
==================
- refined usage and options for "py.cleanup"::
@@ -2762,8 +2877,8 @@ Bug fixes:
- fix plugin links
1.1.1
=====
1.1.1 (2009-11-24)
==================
- moved dist/looponfailing from py.test core into a new
separately released pytest-xdist plugin.
@@ -2846,8 +2961,8 @@ Bug fixes:
- fix docs, fix internal bin/ script generation
1.1.0
=====
1.1.0 (2009-11-05)
==================
- introduce automatic plugin registration via 'pytest11'
entrypoints via setuptools' pkg_resources.iter_entry_points
@@ -2915,7 +3030,7 @@ Bug fixes:
* add the ability to specify a path for py.lookup to search in
* fix a funcarg cached_setup bug probably only occuring
* fix a funcarg cached_setup bug probably only occurring
in distributed testing and "module" scope with teardown.
* many fixes and changes for making the code base python3 compatible,
@@ -2950,16 +3065,16 @@ Bug fixes:
* simplified internal localpath implementation
1.0.2
=====
1.0.2 (2009-08-27)
==================
* fixing packaging issues, triggered by fedora redhat packaging,
also added doc, examples and contrib dirs to the tarball.
* added a documentation link to the new django plugin.
1.0.1
=====
1.0.1 (2009-08-19)
==================
* added a 'pytest_nose' plugin which handles nose.SkipTest,
nose-style function/method/generator setup/teardown and
@@ -2992,14 +3107,14 @@ Bug fixes:
* simplified multicall mechanism and plugin architecture,
renamed some internal methods and argnames
1.0.0
=====
1.0.0 (2009-08-04)
==================
* more terse reporting try to show filesystem path relatively to current dir
* improve xfail output a bit
1.0.0b9
=======
1.0.0b9 (2009-07-31)
====================
* cleanly handle and report final teardown of test setup
@@ -3032,8 +3147,8 @@ Bug fixes:
* item.repr_failure(excinfo) instead of item.repr_failure(excinfo, outerr)
1.0.0b8
=======
1.0.0b8 (2009-07-22)
====================
* pytest_unittest-plugin is now enabled by default
@@ -3086,8 +3201,8 @@ Bug fixes:
* make __name__ == "__channelexec__" for remote_exec code
1.0.0b3
=======
1.0.0b3 (2009-06-19)
====================
* plugin classes are removed: one now defines
hooks directly in conftest.py or global pytest_*.py
@@ -3181,10 +3296,10 @@ serve as a reference for developers.
* fixed issue with 2.5 type representations in py.test [45483, 45484]
* made that internal reporting issues displaying is done atomically in py.test
[45518]
* made that non-existing files are igored by the py.lookup script [45519]
* made that non-existing files are ignored by the py.lookup script [45519]
* improved exception name creation in py.test [45535]
* made that less threads are used in execnet [merge in 45539]
* removed lock required for atomical reporting issue displaying in py.test
* removed lock required for atomic reporting issue displaying in py.test
[45545]
* removed globals from execnet [45541, 45547]
* refactored cleanup mechanics, made that setDaemon is set to 1 to make atexit

View File

@@ -79,6 +79,16 @@ Pytest could always use more documentation. What exactly is needed?
You can also edit documentation files directly in the GitHub web interface,
without using a local copy. This can be convenient for small fixes.
.. note::
Build the documentation locally with the following command:
.. code:: bash
$ tox -e docs
The built documentation should be available in the ``doc/en/_build/``.
Where 'en' refers to the documentation language.
.. _submitplugin:
@@ -199,13 +209,10 @@ but here is a simple overview:
You need to have Python 2.7 and 3.5 available in your system. Now
running tests is as simple as issuing this command::
$ python3 runtox.py -e linting,py27,py35
$ tox -e linting,py27,py35
This command will run tests via the "tox" tool against Python 2.7 and 3.5
and also perform "lint" coding-style checks. ``runtox.py`` is
a thin wrapper around ``tox`` which installs from a development package
index where newer (not yet released to PyPI) versions of dependencies
(especially ``py``) might be present.
and also perform "lint" coding-style checks.
#. You can now edit your local working copy.
@@ -214,11 +221,11 @@ but here is a simple overview:
To run tests on Python 2.7 and pass options to pytest (e.g. enter pdb on
failure) to pytest you can do::
$ python3 runtox.py -e py27 -- --pdb
$ tox -e py27 -- --pdb
Or to only run tests in a particular test module on Python 3.5::
$ python3 runtox.py -e py35 -- testing/test_config.py
$ tox -e py35 -- testing/test_config.py
#. Commit and push once your tests pass and you are happy with your change(s)::

View File

@@ -9,24 +9,28 @@ include HOWTORELEASE.rst
include tox.ini
include setup.py
include .coveragerc
recursive-include scripts *.py
recursive-include scripts *.bat
include plugin-test.sh
include requirements-docs.txt
include runtox.py
include .coveragerc
recursive-include bench *.py
recursive-include extra *.py
graft testing
graft doc
prune doc/en/_build
exclude _pytest/impl
graft _pytest/vendored_packages
recursive-exclude * *.pyc *.pyo
recursive-exclude testing/.hypothesis *
recursive-exclude testing/freeze/~ *
recursive-exclude testing/freeze/build *
recursive-exclude testing/freeze/dist *
exclude appveyor/install.ps1
exclude appveyor.yml
exclude appveyor
exclude .travis.yml
prune .github

View File

@@ -24,31 +24,31 @@ An example of a simple test:
.. code-block:: python
# content of test_sample.py
def func(x):
def inc(x):
return x + 1
def test_answer():
assert func(3) == 5
assert inc(3) == 5
To execute it::
$ pytest
======= test session starts ========
============================= test session starts =============================
collected 1 items
test_sample.py F
======= FAILURES ========
_______ test_answer ________
================================== FAILURES ===================================
_________________________________ test_answer _________________________________
def test_answer():
> assert func(3) == 5
> assert inc(3) == 5
E assert 4 == 5
E + where 4 = func(3)
E + where 4 = inc(3)
test_sample.py:5: AssertionError
======= 1 failed in 0.12 seconds ========
========================== 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.
@@ -89,7 +89,7 @@ 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 <http://docs.pytest.org/en/latest/changelog.html>`__ page for fixes and enhancements of each version.
License

View File

@@ -1,2 +1,2 @@
#
__version__ = '3.0.4'
__version__ = '3.0.6'

View File

@@ -87,6 +87,7 @@ class FastFilesCompleter:
completion.append(x[prefix_dir:])
return completion
if os.environ.get('_ARGCOMPLETE'):
try:
import argcomplete.completers

View File

@@ -343,6 +343,7 @@ class Traceback(list):
l.append(entry.frame.f_locals)
return None
co_equal = compile('__recursioncache_locals_1 == __recursioncache_locals_2',
'?', 'eval')
@@ -846,6 +847,7 @@ def getrawcode(obj, trycall=True):
return x
return obj
if sys.version_info[:2] >= (3, 5): # RecursionError introduced in 3.5
def is_recursion_error(excinfo):
return excinfo.errisinstance(RecursionError) # noqa

View File

@@ -4,7 +4,6 @@ from bisect import bisect_right
import sys
import inspect, tokenize
import py
from types import ModuleType
cpy_compile = compile
try:
@@ -192,14 +191,6 @@ class Source(object):
if flag & _AST_FLAG:
return co
lines = [(x + "\n") for x in self.lines]
if sys.version_info[0] >= 3:
# XXX py3's inspect.getsourcefile() checks for a module
# and a pep302 __loader__ ... we don't have a module
# at code compile-time so we need to fake it here
m = ModuleType("_pycodecompile_pseudo_module")
py.std.inspect.modulesbyfile[filename] = None
py.std.sys.modules[None] = m
m.__loader__ = 1
py.std.linecache.cache[filename] = (1, None, lines, filename)
return co
@@ -265,6 +256,7 @@ def findsource(obj):
source.lines = [line.rstrip() for line in sourcelines]
return source, lineno
def getsource(obj, **kwargs):
import _pytest._code
obj = _pytest._code.getrawcode(obj)
@@ -275,6 +267,7 @@ def getsource(obj, **kwargs):
assert isinstance(strsrc, str)
return Source(strsrc, **kwargs)
def deindent(lines, offset=None):
if offset is None:
for line in lines:
@@ -288,6 +281,7 @@ def deindent(lines, offset=None):
if offset == 0:
return list(lines)
newlines = []
def readline_generator(lines):
for line in lines:
yield line + '\n'

View File

@@ -29,7 +29,7 @@ def pytest_namespace():
def register_assert_rewrite(*names):
"""Register a module name to be rewritten on import.
"""Register one or more module names to be rewritten on import.
This function will make sure that this module or all modules inside
the package will get their assert statements rewritten.
@@ -80,10 +80,12 @@ def install_importhook(config):
config._assertstate.hook = hook = rewrite.AssertionRewritingHook(config)
sys.meta_path.insert(0, hook)
config._assertstate.trace('installed rewrite import hook')
def undo():
hook = config._assertstate.hook
if hook is not None and hook in sys.meta_path:
sys.meta_path.remove(hook)
config.add_cleanup(undo)
return hook

View File

@@ -80,7 +80,12 @@ class AssertionRewritingHook(object):
tp = desc[2]
if tp == imp.PY_COMPILED:
if hasattr(imp, "source_from_cache"):
fn = imp.source_from_cache(fn)
try:
fn = imp.source_from_cache(fn)
except ValueError:
# Python 3 doesn't like orphaned but still-importable
# .pyc files.
fn = fn[:-1]
else:
fn = fn[:-1]
elif tp != imp.PY_SOURCE:
@@ -181,16 +186,15 @@ class AssertionRewritingHook(object):
"""
already_imported = set(names).intersection(set(sys.modules))
if already_imported:
for name in names:
for name in already_imported:
if name not in self._rewritten_names:
self._warn_already_imported(already_imported)
self._warn_already_imported(name)
self._must_rewrite.update(names)
def _warn_already_imported(self, names):
def _warn_already_imported(self, name):
self.config.warn(
'P1',
'Modules are already imported so can not be re-written: %s' %
','.join(names))
'Module already imported so can not be re-written: %s' % name)
def load_module(self, name):
# If there is an existing module object named 'fullname' in
@@ -276,6 +280,7 @@ def _write_pyc(state, co, source_stat, pyc):
fp.close()
return True
RN = "\r\n".encode("utf-8")
N = "\n".encode("utf-8")

View File

@@ -152,6 +152,7 @@ class CaptureManager:
item.add_report_section(when, "stdout", out)
item.add_report_section(when, "stderr", err)
error_capsysfderror = "cannot use capsys and capfd at the same time"

View File

@@ -19,6 +19,7 @@ except ImportError: # pragma: no cover
# Only available in Python 3.4+ or as a backport
enum = None
_PY3 = sys.version_info > (3, 0)
_PY2 = not _PY3
@@ -26,6 +27,9 @@ _PY2 = not _PY3
NoneType = type(None)
NOTSET = object()
PY36 = sys.version_info[:2] >= (3, 6)
MODULE_NOT_FOUND_ERROR = 'ModuleNotFoundError' if PY36 else 'ImportError'
if hasattr(inspect, 'signature'):
def _format_args(func):
return str(inspect.signature(func))
@@ -42,11 +46,18 @@ REGEX_TYPE = type(re.compile(''))
def is_generator(func):
try:
return _pytest._code.getrawcode(func).co_flags & 32 # generator function
except AttributeError: # builtin functions have no bytecode
# assume them to not be generators
return False
genfunc = inspect.isgeneratorfunction(func)
return genfunc and not iscoroutinefunction(func)
def iscoroutinefunction(func):
"""Return True if func is a decorated coroutine function.
Note: copied and modified from Python 3.5's builtin couroutines.py to avoid import asyncio directly,
which in turns also initializes the "logging" module as side-effect (see issue #8).
"""
return (getattr(func, '_is_coroutine', False) or
(hasattr(inspect, 'iscoroutinefunction') and inspect.iscoroutinefunction(func)))
def getlocation(function, curdir):

View File

@@ -65,9 +65,33 @@ def main(args=None, plugins=None):
class cmdline: # compatibility namespace
main = staticmethod(main)
class UsageError(Exception):
""" error in pytest usage or invocation"""
def filename_arg(path, optname):
""" Argparse type validator for filename arguments.
:path: path of filename
:optname: name of the option
"""
if os.path.isdir(path):
raise UsageError("{0} must be a filename, given: {1}".format(optname, path))
return path
def directory_arg(path, optname):
"""Argparse type validator for directory arguments.
:path: path of directory
:optname: name of the option
"""
if not os.path.isdir(path):
raise UsageError("{0} must be a directory, given: {1}".format(optname, path))
return path
_preinit = []
default_plugins = (
@@ -378,31 +402,26 @@ class PytestPluginManager(PluginManager):
self._import_plugin_specs(os.environ.get("PYTEST_PLUGINS"))
def consider_module(self, mod):
plugins = getattr(mod, 'pytest_plugins', [])
if isinstance(plugins, str):
plugins = [plugins]
self.rewrite_hook.mark_rewrite(*plugins)
self._import_plugin_specs(plugins)
self._import_plugin_specs(getattr(mod, 'pytest_plugins', []))
def _import_plugin_specs(self, spec):
if spec:
if isinstance(spec, str):
spec = spec.split(",")
for import_spec in spec:
self.import_plugin(import_spec)
plugins = _get_plugin_specs_as_list(spec)
for import_spec in plugins:
self.import_plugin(import_spec)
def import_plugin(self, modname):
# most often modname refers to builtin modules, e.g. "pytester",
# "terminal" or "capture". Those plugins are registered under their
# basename for historic purposes but must be imported with the
# _pytest prefix.
assert isinstance(modname, str)
assert isinstance(modname, str), "module name as string required, got %r" % modname
if self.get_plugin(modname) is not None:
return
if modname in builtin_plugins:
importspec = "_pytest." + modname
else:
importspec = modname
self.rewrite_hook.mark_rewrite(importspec)
try:
__import__(importspec)
except ImportError as e:
@@ -423,6 +442,24 @@ class PytestPluginManager(PluginManager):
self.consider_module(mod)
def _get_plugin_specs_as_list(specs):
"""
Parses a list of "plugin specs" and returns a list of plugin names.
Plugin specs can be given as a list of strings separated by "," or already as a list/tuple in
which case it is returned as a list. Specs can also be `None` in which case an
empty list is returned.
"""
if specs is not None:
if isinstance(specs, str):
specs = specs.split(',') if specs else []
if not isinstance(specs, (list, tuple)):
raise UsageError("Plugin specs must be a ','-separated string or a "
"list/tuple of strings for plugin names. Given: %r" % specs)
return list(specs)
return []
class Parser:
""" Parser for command line arguments and ini-file values.
@@ -594,7 +631,7 @@ class Argument:
if typ == 'choice':
warnings.warn(
'type argument to addoption() is a string %r.'
' For parsearg this is optional and when supplied '
' For parsearg this is optional and when supplied'
' should be a type.'
' (options: %s)' % (typ, names),
DeprecationWarning,
@@ -818,9 +855,11 @@ class Notset:
def __repr__(self):
return "<NOTSET>"
notset = Notset()
FILE_OR_DIR = 'file_or_dir'
class Config(object):
""" access to configuration values, pluginmanager and plugin hooks. """
@@ -843,9 +882,11 @@ class Config(object):
self._warn = self.pluginmanager._warn
self.pluginmanager.register(self, "pytestconfig")
self._configured = False
def do_setns(dic):
import pytest
setns(pytest, dic)
self.hook.pytest_namespace.call_historic(do_setns, {})
self.hook.pytest_addoption.call_historic(kwargs=dict(parser=self._parser))
@@ -1001,6 +1042,7 @@ class Config(object):
self.pluginmanager.load_setuptools_entrypoints(entrypoint_name)
self.pluginmanager.consider_env()
self.known_args_namespace = ns = self._parser.parse_known_args(args, namespace=self.option.copy())
confcutdir = self.known_args_namespace.confcutdir
if self.known_args_namespace.confcutdir is None and self.inifile:
confcutdir = py.path.local(self.inifile).dirname
self.known_args_namespace.confcutdir = confcutdir
@@ -1120,7 +1162,10 @@ class Config(object):
if self.getoption("override_ini", None):
for ini_config_list in self.option.override_ini:
for ini_config in ini_config_list:
(key, user_ini_value) = ini_config.split("=", 1)
try:
(key, user_ini_value) = ini_config.split("=", 1)
except ValueError:
raise UsageError("-o/--override-ini expects option=value style.")
if key == name:
value = user_ini_value
return value
@@ -1196,25 +1241,20 @@ def getcfg(args, warnfunc=None):
return None, None, None
def get_common_ancestor(args):
# args are what we get after early command line parsing (usually
# strings, but can be py.path.local objects as well)
def get_common_ancestor(paths):
common_ancestor = None
for arg in args:
if str(arg)[0] == "-":
continue
p = py.path.local(arg)
if not p.exists():
for path in paths:
if not path.exists():
continue
if common_ancestor is None:
common_ancestor = p
common_ancestor = path
else:
if p.relto(common_ancestor) or p == common_ancestor:
if path.relto(common_ancestor) or path == common_ancestor:
continue
elif common_ancestor.relto(p):
common_ancestor = p
elif common_ancestor.relto(path):
common_ancestor = path
else:
shared = p.common(common_ancestor)
shared = path.common(common_ancestor)
if shared is not None:
common_ancestor = shared
if common_ancestor is None:
@@ -1225,9 +1265,29 @@ def get_common_ancestor(args):
def get_dirs_from_args(args):
return [d for d in (py.path.local(x) for x in args
if not str(x).startswith("-"))
if d.exists()]
def is_option(x):
return str(x).startswith('-')
def get_file_part_from_node_id(x):
return str(x).split('::')[0]
def get_dir_from_path(path):
if path.isdir():
return path
return py.path.local(path.dirname)
# These look like paths but may not exist
possible_paths = (
py.path.local(get_file_part_from_node_id(arg))
for arg in args
if not is_option(arg)
)
return [
get_dir_from_path(path)
for path in possible_paths
if path.exists()
]
def determine_setup(inifile, args, warnfunc=None):

View File

@@ -31,10 +31,12 @@ def pytest_configure(config):
pytestPDB._pdb_cls = pdb_cls
old = (pdb.set_trace, pytestPDB._pluginmanager)
def fin():
pdb.set_trace, pytestPDB._pluginmanager = old
pytestPDB._config = None
pytestPDB._pdb_cls = pdb.Pdb
pdb.set_trace = pytest.set_trace
pytestPDB._pluginmanager = config.pluginmanager
pytestPDB._config = config

View File

@@ -32,11 +32,13 @@ scope2props["function"] = scope2props["instance"] + ("function", "keywords")
def scopeproperty(name=None, doc=None):
def decoratescope(func):
scopename = name or func.__name__
def provide(self):
if func.__name__ in scope2props[self.scope]:
return func(self)
raise AttributeError("%s not available in %s-scoped context" % (
scopename, self.scope))
return property(provide, None, None, func.__doc__)
return decoratescope

View File

@@ -23,7 +23,7 @@ def pytest_addoption(parser):
group._addoption(
'-o', '--override-ini', nargs='*', dest="override_ini",
action="append",
help="override config option, e.g. `-o xfail_strict=True`.")
help="override config option with option=value style, e.g. `-o xfail_strict=True`.")
@pytest.hookimpl(hookwrapper=True)
@@ -41,12 +41,14 @@ def pytest_cmdline_parse():
config.trace.root.setwriter(debugfile.write)
undo_tracing = config.pluginmanager.enable_tracing()
sys.stderr.write("writing pytestdebug information to %s\n" % path)
def unset_tracing():
debugfile.close()
sys.stderr.write("wrote pytestdebug information to %s\n" %
debugfile.name)
config.trace.root.setwriter(None)
undo_tracing()
config.add_cleanup(unset_tracing)
def pytest_cmdline_main(config):

View File

@@ -8,12 +8,14 @@ Based on initial code from Ross Lawley.
# Output conforms to https://github.com/jenkinsci/xunit-plugin/blob/master/
# src/main/resources/org/jenkinsci/plugins/xunit/types/model/xsd/junit-10.xsd
import functools
import py
import os
import re
import sys
import time
import pytest
from _pytest.config import filename_arg
# Python 2.X and 3.X compatibility
if sys.version_info[0] < 3:
@@ -27,6 +29,7 @@ else:
class Junit(py.xml.Namespace):
pass
# We need to get the subset of the invalid unicode ranges according to
# XML 1.0 which are valid in this python build. Hence we calculate
# this dynamically instead of hardcoding it. The spec range of valid
@@ -213,6 +216,7 @@ def pytest_addoption(parser):
action="store",
dest="xmlpath",
metavar="path",
type=functools.partial(filename_arg, optname="--junitxml"),
default=None,
help="create junit-xml style report file at given path.")
group.addoption(

View File

@@ -1,4 +1,5 @@
""" core implementation of testing process: init, session, runtest loop. """
import functools
import os
import sys
@@ -11,6 +12,7 @@ try:
except ImportError:
from UserDict import DictMixin as MappingMixin
from _pytest.config import directory_arg
from _pytest.runner import collect_one_node
tracebackcutdir = py.path.local(_pytest.__file__).dirpath()
@@ -58,7 +60,7 @@ def pytest_addoption(parser):
# when changing this to --conf-cut-dir, config.py Conftest.setinitial
# needs upgrading as well
group.addoption('--confcutdir', dest="confcutdir", default=None,
metavar="dir",
metavar="dir", type=functools.partial(directory_arg, optname="--confcutdir"),
help="only load conftest.py's relative to specified dir.")
group.addoption('--noconftest', action="store_true",
dest="noconftest", default=False,
@@ -188,12 +190,22 @@ class FSHookProxy:
self.__dict__[name] = x
return x
def compatproperty(name):
def fget(self):
# deprecated - use pytest.name
return getattr(pytest, name)
class _CompatProperty(object):
def __init__(self, name):
self.name = name
def __get__(self, obj, owner):
if obj is None:
return self
# TODO: reenable in the features branch
# warnings.warn(
# "usage of {owner!r}.{name} is deprecated, please use pytest.{name} instead".format(
# name=self.name, owner=type(owner).__name__),
# PendingDeprecationWarning, stacklevel=2)
return getattr(pytest, self.name)
return property(fget)
class NodeKeywords(MappingMixin):
def __init__(self, node):
@@ -265,19 +277,23 @@ class Node(object):
""" fspath sensitive hook proxy used to call pytest hooks"""
return self.session.gethookproxy(self.fspath)
Module = compatproperty("Module")
Class = compatproperty("Class")
Instance = compatproperty("Instance")
Function = compatproperty("Function")
File = compatproperty("File")
Item = compatproperty("Item")
Module = _CompatProperty("Module")
Class = _CompatProperty("Class")
Instance = _CompatProperty("Instance")
Function = _CompatProperty("Function")
File = _CompatProperty("File")
Item = _CompatProperty("Item")
def _getcustomclass(self, name):
cls = getattr(self, name)
if cls != getattr(pytest, name):
py.log._apiwarn("2.0", "use of node.%s is deprecated, "
"use pytest_pycollect_makeitem(...) to create custom "
"collection nodes" % name)
maybe_compatprop = getattr(type(self), name)
if isinstance(maybe_compatprop, _CompatProperty):
return getattr(pytest, name)
else:
cls = getattr(self, name)
# TODO: reenable in the features branch
# warnings.warn("use of node.%s is deprecated, "
# "use pytest_pycollect_makeitem(...) to create custom "
# "collection nodes" % name, category=DeprecationWarning)
return cls
def __repr__(self):
@@ -535,7 +551,6 @@ class Session(FSCollector):
def __init__(self, config):
FSCollector.__init__(self, config.rootdir, parent=None,
config=config, session=self)
self._fs2hookproxy = {}
self.testsfailed = 0
self.testscollected = 0
self.shouldstop = False
@@ -566,23 +581,18 @@ class Session(FSCollector):
return path in self._initialpaths
def gethookproxy(self, fspath):
try:
return self._fs2hookproxy[fspath]
except KeyError:
# check if we have the common case of running
# hooks with all conftest.py filesall conftest.py
pm = self.config.pluginmanager
my_conftestmodules = pm._getconftestmodules(fspath)
remove_mods = pm._conftest_plugins.difference(my_conftestmodules)
if remove_mods:
# one or more conftests are not in use at this fspath
proxy = FSHookProxy(fspath, pm, remove_mods)
else:
# all plugis are active for this fspath
proxy = self.config.hook
self._fs2hookproxy[fspath] = proxy
return proxy
# check if we have the common case of running
# hooks with all conftest.py filesall conftest.py
pm = self.config.pluginmanager
my_conftestmodules = pm._getconftestmodules(fspath)
remove_mods = pm._conftest_plugins.difference(my_conftestmodules)
if remove_mods:
# one or more conftests are not in use at this fspath
proxy = FSHookProxy(fspath, pm, remove_mods)
else:
# all plugis are active for this fspath
proxy = self.config.hook
return proxy
def perform_collect(self, args=None, genitems=True):
hook = self.config.hook
@@ -704,10 +714,9 @@ class Session(FSCollector):
path = self.config.invocation_dir.join(relpath, abs=True)
if not path.check():
if self.config.option.pyargs:
msg = "file or package not found: "
raise pytest.UsageError("file or package not found: " + arg + " (missing __init__.py?)")
else:
msg = "file not found: "
raise pytest.UsageError(msg + arg)
raise pytest.UsageError("file not found: " + arg)
parts[0] = path
return parts

View File

@@ -54,6 +54,8 @@ def pytest_cmdline_main(config):
tw.line()
config._ensure_unconfigure()
return 0
pytest_cmdline_main.tryfirst = True

View File

@@ -11,7 +11,7 @@ RE_IMPORT_ERROR_NAME = re.compile("^No module named (.*)$")
@pytest.fixture
def monkeypatch(request):
def monkeypatch():
"""The returned ``monkeypatch`` fixture provides these
helper methods to modify objects, dictionaries or os.environ::
@@ -30,8 +30,8 @@ def monkeypatch(request):
will be raised if the set/deletion operation has no target.
"""
mpatch = MonkeyPatch()
request.addfinalizer(mpatch.undo)
return mpatch
yield mpatch
mpatch.undo()
def resolve(name):

View File

@@ -11,6 +11,7 @@ def pytest_addoption(parser):
choices=['failed', 'all'],
help="send failed|all info to bpaste.net pastebin service.")
@pytest.hookimpl(trylast=True)
def pytest_configure(config):
import py
@@ -23,13 +24,16 @@ def pytest_configure(config):
# pastebin file will be utf-8 encoded binary file
config._pastebinfile = tempfile.TemporaryFile('w+b')
oldwrite = tr._tw.write
def tee_write(s, **kwargs):
oldwrite(s, **kwargs)
if py.builtin._istext(s):
s = s.encode('utf-8')
config._pastebinfile.write(s)
tr._tw.write = tee_write
def pytest_unconfigure(config):
if hasattr(config, '_pastebinfile'):
# get terminal contents and delete file
@@ -45,6 +49,7 @@ def pytest_unconfigure(config):
pastebinurl = create_new_paste(sessionlog)
tr.write_line("pastebin session-log: %s\n" % pastebinurl)
def create_new_paste(contents):
"""
Creates a new paste using bpaste.net service.
@@ -72,6 +77,7 @@ def create_new_paste(contents):
else:
return 'bad response: ' + response
def pytest_terminal_summary(terminalreporter):
import _pytest.config
if terminalreporter.config.option.pastebin != "failed":

View File

@@ -367,6 +367,7 @@ class RunResult:
for num, cat in outcomes:
d[cat] = int(num)
return d
raise ValueError("Pytest terminal report not found")
def assert_outcomes(self, passed=0, skipped=0, failed=0):
""" assert that the specified outcomes appear with the respective
@@ -446,9 +447,9 @@ class Testdir:
the module is re-imported.
"""
for name in set(sys.modules).difference(self._savemodulekeys):
# it seems zope.interfaces is keeping some state
# (used by twisted related tests)
if name != "zope.interface":
# zope.interface (used by twisted-related tests) keeps internal
# state and can't be deleted
if not name.startswith("zope.interface"):
del sys.modules[name]
def make_hook_recorder(self, pluginmanager):
@@ -478,11 +479,14 @@ class Testdir:
ret = None
for name, value in items:
p = self.tmpdir.join(name).new(ext=ext)
p.dirpath().ensure_dir()
source = Source(value)
def my_totext(s, encoding="utf-8"):
if py.builtin._isbytes(s):
s = py.builtin._totext(s, encoding=encoding)
return s
source_unicode = "\n".join([my_totext(line) for line in source.lines])
source = py.builtin._totext(source_unicode)
content = source.strip().encode("utf-8") # + "\n"
@@ -692,12 +696,15 @@ class Testdir:
# warning which will trigger to say they can no longer be
# re-written, which is fine as they are already re-written.
orig_warn = AssertionRewritingHook._warn_already_imported
def revert():
AssertionRewritingHook._warn_already_imported = orig_warn
self.request.addfinalizer(revert)
AssertionRewritingHook._warn_already_imported = lambda *a: None
rec = []
class Collect:
def pytest_configure(x, config):
rec.append(self.make_hook_recorder(config.pluginmanager))
@@ -732,10 +739,13 @@ class Testdir:
try:
reprec = self.inline_run(*args, **kwargs)
except SystemExit as e:
class reprec:
ret = e.args[0]
except Exception:
traceback.print_exc()
class reprec:
ret = 3
finally:

View File

@@ -214,9 +214,12 @@ class PyobjMixin(PyobjContext):
if obj is None:
self._obj = obj = self._getobj()
return obj
def fset(self, value):
self._obj = value
return property(fget, fset, None, "underlying python object")
obj = obj()
def _getobj(self):
@@ -1416,6 +1419,9 @@ class ApproxNonIterable(object):
self.rel = rel
def __repr__(self):
if isinstance(self.expected, complex):
return str(self.expected)
# Infinities aren't compared using tolerances, so don't show a
# tolerance.
if math.isinf(self.expected):
@@ -1428,16 +1434,10 @@ class ApproxNonIterable(object):
except ValueError:
vetted_tolerance = '???'
plus_minus = u'{0} \u00b1 {1}'.format(self.expected, vetted_tolerance)
# In python2, __repr__() must return a string (i.e. not a unicode
# object). In python3, __repr__() must return a unicode object
# (although now strings are unicode objects and bytes are what
# strings were).
if sys.version_info[0] == 2:
return plus_minus.encode('utf-8')
return '{0} +- {1}'.format(self.expected, vetted_tolerance)
else:
return plus_minus
return u'{0} \u00b1 {1}'.format(self.expected, vetted_tolerance)
def __eq__(self, actual):
# Short-circuit exact equality.

View File

@@ -223,4 +223,7 @@ class WarningsChecker(WarningsRecorder):
if self.expected_warning is not None:
if not any(r.category in self.expected_warning for r in self):
__tracebackhide__ = True
pytest.fail("DID NOT WARN")
pytest.fail("DID NOT WARN. No warnings of type {0} was emitted. "
"The list of emitted warnings is: {1}.".format(
self.expected_warning,
[each.message for each in self]))

View File

@@ -515,8 +515,10 @@ def exit(msg):
__tracebackhide__ = True
raise Exit(msg)
exit.Exception = Exit
def skip(msg=""):
""" skip an executing test with the given message. Note: it's usually
better to use the pytest.mark.skipif marker to declare a test to be
@@ -525,8 +527,11 @@ def skip(msg=""):
"""
__tracebackhide__ = True
raise Skipped(msg=msg)
skip.Exception = Skipped
def fail(msg="", pytrace=True):
""" explicitly fail an currently-executing test with the given Message.
@@ -535,6 +540,8 @@ def fail(msg="", pytrace=True):
"""
__tracebackhide__ = True
raise Failed(msg=msg, pytrace=pytrace)
fail.Exception = Failed

View File

@@ -5,9 +5,9 @@ import sys
def pytest_addoption(parser):
group = parser.getgroup("debugconfig")
group.addoption('--setuponly', '--setup-only', action="store_true",
help="only setup fixtures, don't execute the tests.")
help="only setup fixtures, do not execute tests.")
group.addoption('--setupshow', '--setup-show', action="store_true",
help="show setup fixtures while executing the tests.")
help="show setup of fixtures while executing tests.")
@pytest.hookimpl(hookwrapper=True)

View File

@@ -25,8 +25,10 @@ def pytest_configure(config):
if config.option.runxfail:
old = pytest.xfail
config._cleanup.append(lambda: setattr(pytest, "xfail", old))
def nop(*args, **kwargs):
pass
nop.Exception = XFailed
setattr(pytest, "xfail", nop)
@@ -44,7 +46,7 @@ def pytest_configure(config):
)
config.addinivalue_line("markers",
"xfail(condition, reason=None, run=True, raises=None, strict=False): "
"mark the the test function as an expected failure if eval(condition) "
"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 "
@@ -65,6 +67,8 @@ def xfail(reason=""):
""" xfail an executing test or setup functions with the given reason."""
__tracebackhide__ = True
raise XFailed(reason)
xfail.Exception = XFailed

View File

@@ -81,6 +81,7 @@ def get_user():
except (ImportError, KeyError):
return None
# backward compatibility
TempdirHandler = TempdirFactory

View File

@@ -186,6 +186,7 @@ def pytest_runtest_protocol(item):
ut = sys.modules['twisted.python.failure']
Failure__init__ = ut.Failure.__init__
check_testcase_implements_trial_reporter()
def excstore(self, exc_value=None, exc_type=None, exc_tb=None,
captureVars=None):
if exc_value is None:
@@ -199,6 +200,7 @@ def pytest_runtest_protocol(item):
captureVars=captureVars)
except TypeError:
Failure__init__(self, exc_value, exc_type, exc_tb)
ut.Failure.__init__ = excstore
yield
ut.Failure.__init__ = Failure__init__

View File

@@ -6,32 +6,37 @@ environment:
# https://www.appveyor.com/docs/build-configuration#secure-variables
matrix:
# create multiple jobs to execute a set of tox runs on each; this is to workaround having
# builds timing out in AppVeyor
# pypy is disabled until #1963 gets fixed
- TOXENV: "linting,py26,py27,py33,py34,py35"
- TOXENV: "py27-pexpect,py27-xdist,py27-trial,py35-pexpect,py35-xdist,py35-trial"
- TOXENV: "py27-nobyte,doctesting,freeze,docs"
# coveralls is not in the default env list
- TOXENV: "coveralls"
# note: please use "tox --listenvs" to populate the build matrix below
- TOXENV: "linting"
- TOXENV: "py26"
- TOXENV: "py27"
- TOXENV: "py33"
- TOXENV: "py34"
- TOXENV: "py35"
- TOXENV: "py36"
- TOXENV: "pypy"
- TOXENV: "py27-pexpect"
- TOXENV: "py27-xdist"
- TOXENV: "py27-trial"
- TOXENV: "py35-pexpect"
- TOXENV: "py35-xdist"
- TOXENV: "py35-trial"
- TOXENV: "py27-nobyte"
- TOXENV: "doctesting"
- TOXENV: "freeze"
- TOXENV: "docs"
install:
- echo Installed Pythons
- dir c:\Python*
# install pypy using choco (redirect to a file and write to console in case
# choco install returns non-zero, because choco install python.pypy is too
# noisy)
# pypy is disabled until #1963 gets fixed
#- choco install python.pypy > pypy-inst.log 2>&1 || (type pypy-inst.log & exit /b 1)
#- set PATH=C:\tools\pypy\pypy;%PATH% # so tox can find pypy
#- echo PyPy installed
#- pypy --version
- if "%TOXENV%" == "pypy" call scripts\install-pypy.bat
- C:\Python35\python -m pip install tox
build: false # Not a C# project, build stuff at the test step instead.
test_script:
- C:\Python35\python -m tox
# coveralls is not in tox's envlist, plus for PRs the secure variable
# is not defined so we have to check for it
- if defined COVERALLS_REPO_TOKEN C:\Python35\python -m tox -e coveralls
- call scripts\call-tox.bat

View File

@@ -6,6 +6,8 @@ Release announcements
:maxdepth: 2
release-3.0.6
release-3.0.5
release-3.0.4
release-3.0.3
release-3.0.2

View File

@@ -63,9 +63,9 @@ Changes between 2.0.1 and 2.0.2
this.
- fixed typos in the docs (thanks Victor Garcia, Brianna Laugher) and particular
thanks to Laura Creighton who also revieved parts of the documentation.
thanks to Laura Creighton who also reviewed parts of the documentation.
- fix slighly wrong output of verbose progress reporting for classes
- fix slightly wrong output of verbose progress reporting for classes
(thanks Amaury)
- more precise (avoiding of) deprecation warnings for node.Class|Function accesses

View File

@@ -13,7 +13,7 @@ If you want to install or upgrade pytest, just type one of::
easy_install -U pytest
There also is a bugfix release 1.6 of pytest-xdist, the plugin
that enables seemless distributed and "looponfail" testing for Python.
that enables seamless distributed and "looponfail" testing for Python.
best,
holger krekel
@@ -33,7 +33,7 @@ Changes between 2.0.2 and 2.0.3
- don't require zlib (and other libs) for genscript plugin without
--genscript actually being used.
- speed up skips (by not doing a full traceback represenation
- speed up skips (by not doing a full traceback representation
internally)
- fix issue37: avoid invalid characters in junitxml's output

View File

@@ -2,7 +2,7 @@ pytest-2.2.1: bug fixes, perfect teardowns
===========================================================================
pytest-2.2.1 is a minor backward-compatible release of the the py.test
pytest-2.2.1 is a minor backward-compatible release of the py.test
testing tool. It contains bug fixes and little improvements, including
documentation fixes. If you are using the distributed testing
pluginmake sure to upgrade it to pytest-xdist-1.8.

View File

@@ -29,7 +29,7 @@ Changes between 2.2.3 and 2.2.4
- fix issue with unittest: now @unittest.expectedFailure markers should
be processed correctly (you can also use @pytest.mark markers)
- document integration with the extended distribute/setuptools test commands
- fix issue 140: propperly get the real functions
- fix issue 140: properly get the real functions
of bound classmethods for setup/teardown_class
- fix issue #141: switch from the deceased paste.pocoo.org to bpaste.net
- fix issue #143: call unconfigure/sessionfinish always when

View File

@@ -89,7 +89,7 @@ Changes between 2.2.4 and 2.3.0
- fix issue128: show captured output when capsys/capfd are used
- fix issue179: propperly show the dependency chain of factories
- fix issue179: properly show the dependency chain of factories
- pluginmanager.register(...) now raises ValueError if the
plugin has been already registered or the name is taken
@@ -130,5 +130,5 @@ Changes between 2.2.4 and 2.3.0
- don't show deselected reason line if there is none
- py.test -vv will show all of assert comparisations instead of truncating
- py.test -vv will show all of assert comparisons instead of truncating

View File

@@ -1,7 +1,7 @@
pytest-2.3.2: some fixes and more traceback-printing speed
===========================================================================
pytest-2.3.2 is a another stabilization release:
pytest-2.3.2 is another stabilization release:
- issue 205: fixes a regression with conftest detection
- issue 208/29: fixes traceback-printing speed in some bad cases

View File

@@ -1,7 +1,7 @@
pytest-2.3.3: integration fixes, py24 suport, ``*/**`` shown in traceback
pytest-2.3.3: integration fixes, py24 support, ``*/**`` shown in traceback
===========================================================================
pytest-2.3.3 is a another stabilization release of the py.test tool
pytest-2.3.3 is another stabilization release of the py.test tool
which offers uebersimple assertions, scalable fixture mechanisms
and deep customization for testing with Python. Particularly,
this release provides:
@@ -46,7 +46,7 @@ Changes between 2.3.2 and 2.3.3
- fix issue209 - reintroduce python2.4 support by depending on newer
pylib which re-introduced statement-finding for pre-AST interpreters
- nose support: only call setup if its a callable, thanks Andrew
- nose support: only call setup if it's a callable, thanks Andrew
Taumoefolau
- fix issue219 - add py2.4-3.3 classifiers to TROVE list

View File

@@ -44,11 +44,11 @@ Changes between 2.3.4 and 2.3.5
(thanks Adam Goucher)
- Issue 265 - integrate nose setup/teardown with setupstate
so it doesnt try to teardown if it did not setup
so it doesn't try to teardown if it did not setup
- issue 271 - dont write junitxml on slave nodes
- issue 271 - don't write junitxml on slave nodes
- Issue 274 - dont try to show full doctest example
- Issue 274 - don't try to show full doctest example
when doctest does not know the example location
- issue 280 - disable assertion rewriting on buggy CPython 2.6.0
@@ -84,7 +84,7 @@ Changes between 2.3.4 and 2.3.5
- allow to specify prefixes starting with "_" when
customizing python_functions test discovery. (thanks Graham Horler)
- improve PYTEST_DEBUG tracing output by puting
- improve PYTEST_DEBUG tracing output by putting
extra data on a new lines with additional indent
- ensure OutcomeExceptions like skip/fail have initialized exception attributes

View File

@@ -36,7 +36,7 @@ a full list of details. A few feature highlights:
- reporting: color the last line red or green depending if
failures/errors occurred or everything passed.
The documentation has been updated to accomodate the changes,
The documentation has been updated to accommodate the changes,
see `http://pytest.org <http://pytest.org>`_
To install or upgrade pytest::
@@ -118,7 +118,7 @@ new features:
- fix issue322: tearDownClass is not run if setUpClass failed. Thanks
Mathieu Agopian for the initial fix. Also make all of pytest/nose
finalizer mimick the same generic behaviour: if a setupX exists and
finalizer mimic the same generic behaviour: if a setupX exists and
fails, don't run teardownX. This internally introduces a new method
"node.addfinalizer()" helper which can only be called during the setup
phase of a node.

View File

@@ -70,7 +70,7 @@ holger krekel
to problems for more than >966 non-function scoped parameters).
- fix issue290 - there is preliminary support now for parametrizing
with repeated same values (sometimes useful to to test if calling
with repeated same values (sometimes useful to test if calling
a second time works as with the first time).
- close issue240 - document precisely how pytest module importing
@@ -149,7 +149,7 @@ holger krekel
would not work correctly because pytest assumes @pytest.mark.some
gets a function to be decorated already. We now at least detect if this
arg is an lambda and thus the example will work. Thanks Alex Gaynor
arg is a lambda and thus the example will work. Thanks Alex Gaynor
for bringing it up.
- xfail a test on pypy that checks wrong encoding/ascii (pypy does

View File

@@ -60,5 +60,5 @@ holger krekel
- fix issue429: comparing byte strings with non-ascii chars in assert
expressions now work better. Thanks Floris Bruynooghe.
- make capfd/capsys.capture private, its unused and shouldnt be exposed
- make capfd/capsys.capture private, its unused and shouldn't be exposed

View File

@@ -42,7 +42,7 @@ Changes 2.6.3
- fix conftest related fixture visibility issue: when running with a
CWD outside of a test package pytest would get fixture discovery wrong.
Thanks to Wolfgang Schnerring for figuring out a reproducable example.
Thanks to Wolfgang Schnerring for figuring out a reproducible example.
- Introduce pytest_enter_pdb hook (needed e.g. by pytest_timeout to cancel the
timeout when interactively entering pdb). Thanks Wolfgang Schnerring.

View File

@@ -32,7 +32,7 @@ The py.test Development Team
explanations. Thanks Carl Meyer for the report and test case.
- fix issue553: properly handling inspect.getsourcelines failures in
FixtureLookupError which would lead to to an internal error,
FixtureLookupError which would lead to an internal error,
obfuscating the original problem. Thanks talljosh for initial
diagnose/patch and Bruno Oliveira for final patch.

View File

@@ -46,7 +46,7 @@ The py.test Development Team
Thanks `@astraw38`_ for reporting the issue (`#1496`_) and `@tomviner`_
for PR the (`#1524`_).
* Fix win32 path issue when puttinging custom config file with absolute path
* Fix win32 path issue when putting custom config file with absolute path
in ``pytest.main("-c your_absolute_path")``.
* Fix maximum recursion depth detection when raised error class is not aware

View File

@@ -0,0 +1,27 @@
pytest-3.0.5
============
pytest 3.0.5 has just been released to PyPI.
This is a bug-fix release, being a drop-in replacement. To upgrade::
pip install --upgrade pytest
The changelog is available at http://doc.pytest.org/en/latest/changelog.html.
Thanks to all who contributed to this release, among them:
* Ana Vojnovic
* Bruno Oliveira
* Daniel Hahler
* Duncan Betts
* Igor Starikov
* Ismail
* Luke Murphy
* Ned Batchelder
* Ronny Pfannschmidt
* Sebastian Ramacher
* nmundar
Happy testing,
The pytest Development Team

View File

@@ -0,0 +1,33 @@
pytest-3.0.6
============
pytest 3.0.6 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:
* Andreas Pelme
* Bruno Oliveira
* Dmitry Malinovsky
* Eli Boyarski
* Jakub Wilk
* Jeff Widman
* Loïc Estève
* Luke Murphy
* Miro Hrončok
* Oscar Hellström
* Peter Heatwole
* Philippe Ombredanne
* Ronny Pfannschmidt
* Rutger Prins
* Stefan Scherfke
Happy testing,
The pytest Development Team

View File

@@ -26,7 +26,7 @@ you will see the return value of the function call::
$ pytest test_assert1.py
======= test session starts ========
platform linux -- Python 3.5.2, pytest-3.0.4, py-1.4.31, pluggy-0.4.0
platform linux -- Python 3.5.2, pytest-3.0.6, py-1.4.33, pluggy-0.4.0
rootdir: $REGENDOC_TMPDIR, inifile:
collected 1 items
@@ -170,7 +170,7 @@ if you run this module::
$ pytest test_assert2.py
======= test session starts ========
platform linux -- Python 3.5.2, pytest-3.0.4, py-1.4.31, pluggy-0.4.0
platform linux -- Python 3.5.2, pytest-3.0.6, py-1.4.33, pluggy-0.4.0
rootdir: $REGENDOC_TMPDIR, inifile:
collected 1 items
@@ -262,50 +262,20 @@ Advanced assertion introspection
.. versionadded:: 2.1
Reporting details about a failing assertion is achieved either by rewriting
assert statements before they are run or re-evaluating the assert expression and
recording the intermediate values. Which technique is used depends on the
location of the assert, ``pytest`` configuration, and Python version being used
to run ``pytest``.
By default, ``pytest`` rewrites assert statements in test modules.
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.
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. It does this by using an import
hook to write a new pyc files. Most of the time this works transparently.
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, simply use ``--assert=reinterp`` or
``--assert=plain``. Additionally, rewriting will fail silently if it cannot
write new pycs, i.e. in a read-only filesystem or a zipfile.
If an assert statement has not been rewritten or the Python version is less than
2.6, ``pytest`` falls back on assert reinterpretation. In assert
reinterpretation, ``pytest`` walks the frame of the function containing the
assert statement to discover sub-expression results of the failing assert
statement. You can force ``pytest`` to always use assertion reinterpretation by
passing the ``--assert=reinterp`` option.
Assert reinterpretation has a caveat not present with assert rewriting: If
evaluating the assert expression has side effects you may get a warning that the
intermediate values could not be determined safely. A common example of this
issue is an assertion which reads from a file::
assert f.read() != '...'
If this assertion fails then the re-evaluation will probably succeed!
This is because ``f.read()`` will return an empty string when it is
called the second time during the re-evaluation. However, it is
easy to rewrite the assertion and avoid any trouble::
content = f.read()
assert content != '...'
All assert introspection can be turned off by passing ``--assert=plain``.
interfere. If this is the case, use ``--assert=plain``. Additionally,
rewriting will fail silently if it cannot write new pycs, i.e. in a read-only
filesystem or a zipfile.
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>`_.
@@ -318,3 +288,4 @@ For further information, Benjamin Peterson wrote up `Behind the scenes of pytest
.. versionchanged:: 3.0
Removes the ``--no-assert`` and``--nomagic`` options.
Removes the ``--assert=reinterp`` option.

View File

@@ -80,7 +80,7 @@ If you then run it with ``--lf``::
$ pytest --lf
======= test session starts ========
platform linux -- Python 3.5.2, pytest-3.0.4, py-1.4.31, pluggy-0.4.0
platform linux -- Python 3.5.2, pytest-3.0.6, py-1.4.33, pluggy-0.4.0
run-last-failure: rerun last 2 failures
rootdir: $REGENDOC_TMPDIR, inifile:
collected 50 items
@@ -122,7 +122,7 @@ of ``FF`` and dots)::
$ pytest --ff
======= test session starts ========
platform linux -- Python 3.5.2, pytest-3.0.4, py-1.4.31, pluggy-0.4.0
platform linux -- Python 3.5.2, pytest-3.0.6, py-1.4.33, pluggy-0.4.0
run-last-failure: rerun last 2 failures first
rootdir: $REGENDOC_TMPDIR, inifile:
collected 50 items
@@ -227,7 +227,7 @@ You can always peek at the content of the cache using the
$ py.test --cache-show
======= test session starts ========
platform linux -- Python 3.5.2, pytest-3.0.4, py-1.4.31, pluggy-0.4.0
platform linux -- Python 3.5.2, pytest-3.0.6, py-1.4.33, pluggy-0.4.0
rootdir: $REGENDOC_TMPDIR, inifile:
cachedir: $REGENDOC_TMPDIR/.cache
------------------------------- cache values -------------------------------
@@ -246,7 +246,7 @@ by adding the ``--cache-clear`` option like this::
pytest --cache-clear
This is recommended for invocations from Continous Integration
This is recommended for invocations from Continuous Integration
servers where isolation and correctness is more important
than speed.

View File

@@ -64,7 +64,7 @@ of the failing function and hide the other one::
$ pytest
======= test session starts ========
platform linux -- Python 3.5.2, pytest-3.0.4, py-1.4.31, pluggy-0.4.0
platform linux -- Python 3.5.2, pytest-3.0.6, py-1.4.33, pluggy-0.4.0
rootdir: $REGENDOC_TMPDIR, inifile:
collected 2 items

View File

@@ -303,7 +303,7 @@ texinfo_documents = [
('Holger Krekel@*Benjamin Peterson@*Ronny Pfannschmidt@*'
'Floris Bruynooghe@*others'),
'pytest',
'simple powerful testing with Pytho',
'simple powerful testing with Python',
'Programming',
1),
]

View File

@@ -49,7 +49,7 @@ then you can just invoke ``pytest`` without command line options::
$ pytest
======= test session starts ========
platform linux -- Python 3.5.2, pytest-3.0.4, py-1.4.31, pluggy-0.4.0
platform linux -- Python 3.5.2, pytest-3.0.6, py-1.4.33, pluggy-0.4.0
rootdir: $REGENDOC_TMPDIR, inifile: pytest.ini
collected 1 items

View File

@@ -31,7 +31,7 @@ You can then restrict a test run to only run tests marked with ``webtest``::
$ pytest -v -m webtest
======= test session starts ========
platform linux -- Python 3.5.2, pytest-3.0.4, py-1.4.31, pluggy-0.4.0 -- $PYTHON_PREFIX/bin/python3.5
platform linux -- Python 3.5.2, pytest-3.0.6, py-1.4.33, pluggy-0.4.0 -- $PYTHON_PREFIX/bin/python3.5m
cachedir: .cache
rootdir: $REGENDOC_TMPDIR, inifile:
collecting ... collected 4 items
@@ -45,7 +45,7 @@ Or the inverse, running all tests except the webtest ones::
$ pytest -v -m "not webtest"
======= test session starts ========
platform linux -- Python 3.5.2, pytest-3.0.4, py-1.4.31, pluggy-0.4.0 -- $PYTHON_PREFIX/bin/python3.5
platform linux -- Python 3.5.2, pytest-3.0.6, py-1.4.33, pluggy-0.4.0 -- $PYTHON_PREFIX/bin/python3.5m
cachedir: .cache
rootdir: $REGENDOC_TMPDIR, inifile:
collecting ... collected 4 items
@@ -66,7 +66,7 @@ tests based on their module, class, method, or function name::
$ pytest -v test_server.py::TestClass::test_method
======= test session starts ========
platform linux -- Python 3.5.2, pytest-3.0.4, py-1.4.31, pluggy-0.4.0 -- $PYTHON_PREFIX/bin/python3.5
platform linux -- Python 3.5.2, pytest-3.0.6, py-1.4.33, pluggy-0.4.0 -- $PYTHON_PREFIX/bin/python3.5m
cachedir: .cache
rootdir: $REGENDOC_TMPDIR, inifile:
collecting ... collected 5 items
@@ -79,7 +79,7 @@ You can also select on the class::
$ pytest -v test_server.py::TestClass
======= test session starts ========
platform linux -- Python 3.5.2, pytest-3.0.4, py-1.4.31, pluggy-0.4.0 -- $PYTHON_PREFIX/bin/python3.5
platform linux -- Python 3.5.2, pytest-3.0.6, py-1.4.33, pluggy-0.4.0 -- $PYTHON_PREFIX/bin/python3.5m
cachedir: .cache
rootdir: $REGENDOC_TMPDIR, inifile:
collecting ... collected 4 items
@@ -92,7 +92,7 @@ Or select multiple nodes::
$ pytest -v test_server.py::TestClass test_server.py::test_send_http
======= test session starts ========
platform linux -- Python 3.5.2, pytest-3.0.4, py-1.4.31, pluggy-0.4.0 -- $PYTHON_PREFIX/bin/python3.5
platform linux -- Python 3.5.2, pytest-3.0.6, py-1.4.33, pluggy-0.4.0 -- $PYTHON_PREFIX/bin/python3.5m
cachedir: .cache
rootdir: $REGENDOC_TMPDIR, inifile:
collecting ... collected 8 items
@@ -130,7 +130,7 @@ select tests based on their names::
$ pytest -v -k http # running with the above defined example module
======= test session starts ========
platform linux -- Python 3.5.2, pytest-3.0.4, py-1.4.31, pluggy-0.4.0 -- $PYTHON_PREFIX/bin/python3.5
platform linux -- Python 3.5.2, pytest-3.0.6, py-1.4.33, pluggy-0.4.0 -- $PYTHON_PREFIX/bin/python3.5m
cachedir: .cache
rootdir: $REGENDOC_TMPDIR, inifile:
collecting ... collected 4 items
@@ -144,7 +144,7 @@ And you can also run all tests except the ones that match the keyword::
$ pytest -k "not send_http" -v
======= test session starts ========
platform linux -- Python 3.5.2, pytest-3.0.4, py-1.4.31, pluggy-0.4.0 -- $PYTHON_PREFIX/bin/python3.5
platform linux -- Python 3.5.2, pytest-3.0.6, py-1.4.33, pluggy-0.4.0 -- $PYTHON_PREFIX/bin/python3.5m
cachedir: .cache
rootdir: $REGENDOC_TMPDIR, inifile:
collecting ... collected 4 items
@@ -160,7 +160,7 @@ Or to select "http" and "quick" tests::
$ pytest -k "http or quick" -v
======= test session starts ========
platform linux -- Python 3.5.2, pytest-3.0.4, py-1.4.31, pluggy-0.4.0 -- $PYTHON_PREFIX/bin/python3.5
platform linux -- Python 3.5.2, pytest-3.0.6, py-1.4.33, pluggy-0.4.0 -- $PYTHON_PREFIX/bin/python3.5m
cachedir: .cache
rootdir: $REGENDOC_TMPDIR, inifile:
collecting ... collected 4 items
@@ -205,7 +205,7 @@ You can ask which markers exist for your test suite - the list includes our just
@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.xfail(condition, reason=None, run=True, raises=None, strict=False): mark the 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 http://pytest.org/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.
@@ -352,7 +352,7 @@ the test needs::
$ pytest -E stage2
======= test session starts ========
platform linux -- Python 3.5.2, pytest-3.0.4, py-1.4.31, pluggy-0.4.0
platform linux -- Python 3.5.2, pytest-3.0.6, py-1.4.33, pluggy-0.4.0
rootdir: $REGENDOC_TMPDIR, inifile:
collected 1 items
@@ -364,7 +364,7 @@ and here is one that specifies exactly the environment needed::
$ pytest -E stage1
======= test session starts ========
platform linux -- Python 3.5.2, pytest-3.0.4, py-1.4.31, pluggy-0.4.0
platform linux -- Python 3.5.2, pytest-3.0.6, py-1.4.33, pluggy-0.4.0
rootdir: $REGENDOC_TMPDIR, inifile:
collected 1 items
@@ -381,7 +381,7 @@ The ``--markers`` option always gives you a list of available markers::
@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.xfail(condition, reason=None, run=True, raises=None, strict=False): mark the 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 http://pytest.org/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.
@@ -450,7 +450,7 @@ for your particular platform, you could use the following plugin::
import sys
import pytest
ALL = set("darwin linux2 win32".split())
ALL = set("darwin linux win32".split())
def pytest_runtest_setup(item):
if isinstance(item, item.Function):
@@ -470,7 +470,7 @@ Let's do a little test file to show how this looks like::
def test_if_apple_is_evil():
pass
@pytest.mark.linux2
@pytest.mark.linux
def test_if_linux_works():
pass
@@ -481,32 +481,32 @@ Let's do a little test file to show how this looks like::
def test_runs_everywhere():
pass
then you will see two test skipped and two executed tests as expected::
then you will see two tests skipped and two executed tests as expected::
$ pytest -rs # this option reports skip reasons
======= test session starts ========
platform linux -- Python 3.5.2, pytest-3.0.4, py-1.4.31, pluggy-0.4.0
platform linux -- Python 3.5.2, pytest-3.0.6, py-1.4.33, pluggy-0.4.0
rootdir: $REGENDOC_TMPDIR, inifile:
collected 4 items
test_plat.py sss.
test_plat.py s.s.
======= short test summary info ========
SKIP [3] $REGENDOC_TMPDIR/conftest.py:12: cannot run on platform linux
SKIP [2] $REGENDOC_TMPDIR/conftest.py:12: cannot run on platform linux
======= 1 passed, 3 skipped in 0.12 seconds ========
======= 2 passed, 2 skipped in 0.12 seconds ========
Note that if you specify a platform via the marker-command line option like this::
$ pytest -m linux2
$ pytest -m linux
======= test session starts ========
platform linux -- Python 3.5.2, pytest-3.0.4, py-1.4.31, pluggy-0.4.0
platform linux -- Python 3.5.2, pytest-3.0.6, py-1.4.33, pluggy-0.4.0
rootdir: $REGENDOC_TMPDIR, inifile:
collected 4 items
test_plat.py s
test_plat.py .
======= 3 tests deselected ========
======= 1 skipped, 3 deselected in 0.12 seconds ========
======= 1 passed, 3 deselected in 0.12 seconds ========
then the unmarked-tests will not be run. It is thus a way to restrict the run to the specific tests.
@@ -551,7 +551,7 @@ We can now use the ``-m option`` to select one set::
$ pytest -m interface --tb=short
======= test session starts ========
platform linux -- Python 3.5.2, pytest-3.0.4, py-1.4.31, pluggy-0.4.0
platform linux -- Python 3.5.2, pytest-3.0.6, py-1.4.33, pluggy-0.4.0
rootdir: $REGENDOC_TMPDIR, inifile:
collected 4 items
@@ -573,7 +573,7 @@ or to select both "event" and "interface" tests::
$ pytest -m "interface or event" --tb=short
======= test session starts ========
platform linux -- Python 3.5.2, pytest-3.0.4, py-1.4.31, pluggy-0.4.0
platform linux -- Python 3.5.2, pytest-3.0.6, py-1.4.33, pluggy-0.4.0
rootdir: $REGENDOC_TMPDIR, inifile:
collected 4 items

View File

@@ -27,7 +27,7 @@ now execute the test specification::
nonpython $ pytest test_simple.yml
======= test session starts ========
platform linux -- Python 3.5.2, pytest-3.0.4, py-1.4.31, pluggy-0.4.0
platform linux -- Python 3.5.2, pytest-3.0.6, py-1.4.33, pluggy-0.4.0
rootdir: $REGENDOC_TMPDIR/nonpython, inifile:
collected 2 items
@@ -59,7 +59,7 @@ consulted when reporting in ``verbose`` mode::
nonpython $ pytest -v
======= test session starts ========
platform linux -- Python 3.5.2, pytest-3.0.4, py-1.4.31, pluggy-0.4.0 -- $PYTHON_PREFIX/bin/python3.5
platform linux -- Python 3.5.2, pytest-3.0.6, py-1.4.33, pluggy-0.4.0 -- $PYTHON_PREFIX/bin/python3.5m
cachedir: .cache
rootdir: $REGENDOC_TMPDIR/nonpython, inifile:
collecting ... collected 2 items
@@ -81,7 +81,7 @@ interesting to just look at the collection tree::
nonpython $ pytest --collect-only
======= test session starts ========
platform linux -- Python 3.5.2, pytest-3.0.4, py-1.4.31, pluggy-0.4.0
platform linux -- Python 3.5.2, pytest-3.0.6, py-1.4.33, pluggy-0.4.0
rootdir: $REGENDOC_TMPDIR/nonpython, inifile:
collected 2 items
<YamlFile 'test_simple.yml'>

View File

@@ -130,7 +130,7 @@ objects, they are still using the default pytest representation::
$ pytest test_time.py --collect-only
======= test session starts ========
platform linux -- Python 3.5.2, pytest-3.0.4, py-1.4.31, pluggy-0.4.0
platform linux -- Python 3.5.2, pytest-3.0.6, py-1.4.33, pluggy-0.4.0
rootdir: $REGENDOC_TMPDIR, inifile:
collected 6 items
<Module 'test_time.py'>
@@ -181,7 +181,7 @@ this is a fully self-contained example which you can run with::
$ pytest test_scenarios.py
======= test session starts ========
platform linux -- Python 3.5.2, pytest-3.0.4, py-1.4.31, pluggy-0.4.0
platform linux -- Python 3.5.2, pytest-3.0.6, py-1.4.33, pluggy-0.4.0
rootdir: $REGENDOC_TMPDIR, inifile:
collected 4 items
@@ -194,7 +194,7 @@ If you just collect tests you'll also nicely see 'advanced' and 'basic' as varia
$ pytest --collect-only test_scenarios.py
======= test session starts ========
platform linux -- Python 3.5.2, pytest-3.0.4, py-1.4.31, pluggy-0.4.0
platform linux -- Python 3.5.2, pytest-3.0.6, py-1.4.33, pluggy-0.4.0
rootdir: $REGENDOC_TMPDIR, inifile:
collected 4 items
<Module 'test_scenarios.py'>
@@ -259,7 +259,7 @@ Let's first see how it looks like at collection time::
$ pytest test_backends.py --collect-only
======= test session starts ========
platform linux -- Python 3.5.2, pytest-3.0.4, py-1.4.31, pluggy-0.4.0
platform linux -- Python 3.5.2, pytest-3.0.6, py-1.4.33, pluggy-0.4.0
rootdir: $REGENDOC_TMPDIR, inifile:
collected 2 items
<Module 'test_backends.py'>
@@ -320,7 +320,7 @@ The result of this test will be successful::
$ pytest test_indirect_list.py --collect-only
======= test session starts ========
platform linux -- Python 3.5.2, pytest-3.0.4, py-1.4.31, pluggy-0.4.0
platform linux -- Python 3.5.2, pytest-3.0.6, py-1.4.33, pluggy-0.4.0
rootdir: $REGENDOC_TMPDIR, inifile:
collected 1 items
<Module 'test_indirect_list.py'>
@@ -397,10 +397,12 @@ is to be run with different sets of arguments for its three arguments:
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)::
. $ pytest -rs -q multipython.py
sssssssssssssss.........sss.........sss.........
sssssssssssssssssssssssssssssssssssssssssssss...
======= short test summary info ========
SKIP [21] $REGENDOC_TMPDIR/CWD/multipython.py:23: 'python2.6' not found
27 passed, 21 skipped in 0.12 seconds
SKIP [15] $REGENDOC_TMPDIR/CWD/multipython.py:23: 'python2.6' not found
SKIP [15] $REGENDOC_TMPDIR/CWD/multipython.py:23: 'python3.4' not found
SKIP [15] $REGENDOC_TMPDIR/CWD/multipython.py:23: 'python2.7' not found
3 passed, 45 skipped in 0.12 seconds
Indirect parametrization of optional implementations/imports
--------------------------------------------------------------------
@@ -447,7 +449,7 @@ If you run this with reporting for skips enabled::
$ pytest -rs test_module.py
======= test session starts ========
platform linux -- Python 3.5.2, pytest-3.0.4, py-1.4.31, pluggy-0.4.0
platform linux -- Python 3.5.2, pytest-3.0.6, py-1.4.33, pluggy-0.4.0
rootdir: $REGENDOC_TMPDIR, inifile:
collected 2 items

View File

@@ -95,7 +95,7 @@ the :confval:`python_files`, :confval:`python_classes` and
:confval:`python_functions` configuration options. Example::
# content of pytest.ini
# can also be defined in in tox.ini or setup.cfg file, although the section
# 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
@@ -117,7 +117,7 @@ then the test collection looks like this::
$ pytest --collect-only
======= test session starts ========
platform linux -- Python 3.5.2, pytest-3.0.4, py-1.4.31, pluggy-0.4.0
platform linux -- Python 3.5.2, pytest-3.0.6, py-1.4.33, pluggy-0.4.0
rootdir: $REGENDOC_TMPDIR, inifile: pytest.ini
collected 2 items
<Module 'check_myapp.py'>
@@ -163,7 +163,7 @@ You can always peek at the collection tree without running tests like this::
. $ pytest --collect-only pythoncollection.py
======= test session starts ========
platform linux -- Python 3.5.2, pytest-3.0.4, py-1.4.31, pluggy-0.4.0
platform linux -- Python 3.5.2, pytest-3.0.6, py-1.4.33, pluggy-0.4.0
rootdir: $REGENDOC_TMPDIR, inifile: pytest.ini
collected 3 items
<Module 'CWD/pythoncollection.py'>
@@ -230,7 +230,7 @@ will be left out::
$ pytest --collect-only
======= test session starts ========
platform linux -- Python 3.5.2, pytest-3.0.4, py-1.4.31, pluggy-0.4.0
platform linux -- Python 3.5.2, pytest-3.0.6, py-1.4.33, pluggy-0.4.0
rootdir: $REGENDOC_TMPDIR, inifile: pytest.ini
collected 0 items

View File

@@ -11,7 +11,7 @@ get on the terminal - we are working on that)::
assertion $ pytest failure_demo.py
======= test session starts ========
platform linux -- Python 3.5.2, pytest-3.0.4, py-1.4.31, pluggy-0.4.0
platform linux -- Python 3.5.2, pytest-3.0.6, py-1.4.33, pluggy-0.4.0
rootdir: $REGENDOC_TMPDIR/assertion, inifile:
collected 42 items
@@ -359,7 +359,7 @@ get on the terminal - we are working on that)::
> int(s)
E ValueError: invalid literal for int() with base 10: 'qwe'
<0-codegen $PYTHON_PREFIX/lib/python3.5/site-packages/_pytest/python.py:1204>:1: ValueError
<0-codegen $PYTHON_PREFIX/lib/python3.5/site-packages/_pytest/python.py:1207>:1: ValueError
_______ TestRaises.test_raises_doesnt ________
self = <failure_demo.TestRaises object at 0xdeadbeef>

View File

@@ -113,7 +113,7 @@ directory with the above conftest.py::
$ pytest
======= test session starts ========
platform linux -- Python 3.5.2, pytest-3.0.4, py-1.4.31, pluggy-0.4.0
platform linux -- Python 3.5.2, pytest-3.0.6, py-1.4.33, pluggy-0.4.0
rootdir: $REGENDOC_TMPDIR, inifile:
collected 0 items
@@ -164,7 +164,7 @@ and when running it will see a skipped "slow" test::
$ pytest -rs # "-rs" means report details on the little 's'
======= test session starts ========
platform linux -- Python 3.5.2, pytest-3.0.4, py-1.4.31, pluggy-0.4.0
platform linux -- Python 3.5.2, pytest-3.0.6, py-1.4.33, pluggy-0.4.0
rootdir: $REGENDOC_TMPDIR, inifile:
collected 2 items
@@ -178,7 +178,7 @@ Or run it including the ``slow`` marked test::
$ pytest --runslow
======= test session starts ========
platform linux -- Python 3.5.2, pytest-3.0.4, py-1.4.31, pluggy-0.4.0
platform linux -- Python 3.5.2, pytest-3.0.6, py-1.4.33, pluggy-0.4.0
rootdir: $REGENDOC_TMPDIR, inifile:
collected 2 items
@@ -302,7 +302,7 @@ which will add the string to the test header accordingly::
$ pytest
======= test session starts ========
platform linux -- Python 3.5.2, pytest-3.0.4, py-1.4.31, pluggy-0.4.0
platform linux -- Python 3.5.2, pytest-3.0.6, py-1.4.33, pluggy-0.4.0
project deps: mylib-1.1
rootdir: $REGENDOC_TMPDIR, inifile:
collected 0 items
@@ -327,7 +327,7 @@ which will add info only when run with "--v"::
$ pytest -v
======= test session starts ========
platform linux -- Python 3.5.2, pytest-3.0.4, py-1.4.31, pluggy-0.4.0 -- $PYTHON_PREFIX/bin/python3.5
platform linux -- Python 3.5.2, pytest-3.0.6, py-1.4.33, pluggy-0.4.0 -- $PYTHON_PREFIX/bin/python3.5m
cachedir: .cache
info1: did you know that ...
did you?
@@ -340,7 +340,7 @@ and nothing when run plainly::
$ pytest
======= test session starts ========
platform linux -- Python 3.5.2, pytest-3.0.4, py-1.4.31, pluggy-0.4.0
platform linux -- Python 3.5.2, pytest-3.0.6, py-1.4.33, pluggy-0.4.0
rootdir: $REGENDOC_TMPDIR, inifile:
collected 0 items
@@ -374,7 +374,7 @@ Now we can profile which test functions execute the slowest::
$ pytest --durations=3
======= test session starts ========
platform linux -- Python 3.5.2, pytest-3.0.4, py-1.4.31, pluggy-0.4.0
platform linux -- Python 3.5.2, pytest-3.0.6, py-1.4.33, pluggy-0.4.0
rootdir: $REGENDOC_TMPDIR, inifile:
collected 3 items
@@ -440,7 +440,7 @@ If we run this::
$ pytest -rx
======= test session starts ========
platform linux -- Python 3.5.2, pytest-3.0.4, py-1.4.31, pluggy-0.4.0
platform linux -- Python 3.5.2, pytest-3.0.6, py-1.4.33, pluggy-0.4.0
rootdir: $REGENDOC_TMPDIR, inifile:
collected 4 items
@@ -476,7 +476,7 @@ concept. It's however recommended to have explicit fixture references in your
tests or test classes rather than relying on implicitly executing
setup/teardown functions, especially if they are far away from the actual tests.
Here is a an example for making a ``db`` fixture available in a directory:
Here is an example for making a ``db`` fixture available in a directory:
.. code-block:: python
@@ -519,7 +519,7 @@ We can run this::
$ pytest
======= test session starts ========
platform linux -- Python 3.5.2, pytest-3.0.4, py-1.4.31, pluggy-0.4.0
platform linux -- Python 3.5.2, pytest-3.0.6, py-1.4.33, pluggy-0.4.0
rootdir: $REGENDOC_TMPDIR, inifile:
collected 7 items
@@ -585,7 +585,7 @@ environment you can implement a hook that gets called when the test
"report" object is about to be created. Here we write out all failing
test calls and also access a fixture (if it was used by the test) in
case you want to query/look at it during your post processing. In our
case we just write some informations out to a ``failures`` file:
case we just write some information out to a ``failures`` file:
.. code-block:: python
@@ -627,7 +627,7 @@ and run them::
$ pytest test_module.py
======= test session starts ========
platform linux -- Python 3.5.2, pytest-3.0.4, py-1.4.31, pluggy-0.4.0
platform linux -- Python 3.5.2, pytest-3.0.6, py-1.4.33, pluggy-0.4.0
rootdir: $REGENDOC_TMPDIR, inifile:
collected 2 items
@@ -678,7 +678,7 @@ here is a little example implemented via a local plugin:
outcome = yield
rep = outcome.get_result()
# set an report attribute for each phase of a call, which can
# set a report attribute for each phase of a call, which can
# be "setup", "call", "teardown"
setattr(item, "rep_" + rep.when, rep)
@@ -721,7 +721,7 @@ and run it::
$ pytest -s test_module.py
======= test session starts ========
platform linux -- Python 3.5.2, pytest-3.0.4, py-1.4.31, pluggy-0.4.0
platform linux -- Python 3.5.2, pytest-3.0.6, py-1.4.33, pluggy-0.4.0
rootdir: $REGENDOC_TMPDIR, inifile:
collected 3 items

View File

@@ -66,14 +66,6 @@ This completely avoids previous issues of confusing assertion-reporting.
It also means, that you can use Python's ``-O`` optimization without losing
assertions in test modules.
``pytest`` contains a second, mostly obsolete, assert debugging technique
invoked via ``--assert=reinterpret``: When an ``assert`` statement fails, ``pytest`` re-interprets
the expression part to show intermediate values. This technique suffers
from a caveat that the rewriting does not: If your expression has side
effects (better to avoid them anyway!) the intermediate values may not
be the same, confusing the reinterpreter and obfuscating the initial
error (this is also explained at the command line if it happens).
You can also turn off all assertion interaction using the
``--assert=plain`` option.

View File

@@ -11,7 +11,7 @@ pytest fixtures: explicit, modular, scalable
.. _`xUnit`: http://en.wikipedia.org/wiki/XUnit
.. _`purpose of test fixtures`: http://en.wikipedia.org/wiki/Test_fixture#Software
.. _`Dependency injection`: http://en.wikipedia.org/wiki/Dependency_injection#Definition
.. _`Dependency injection`: http://en.wikipedia.org/wiki/Dependency_injection
The `purpose of test fixtures`_ is to provide a fixed baseline
upon which tests can reliably and repeatedly execute. pytest fixtures
@@ -70,7 +70,7 @@ marked ``smtp`` fixture function. Running the test looks like this::
$ pytest test_smtpsimple.py
======= test session starts ========
platform linux -- Python 3.5.2, pytest-3.0.4, py-1.4.31, pluggy-0.4.0
platform linux -- Python 3.5.2, pytest-3.0.6, py-1.4.33, pluggy-0.4.0
rootdir: $REGENDOC_TMPDIR, inifile:
collected 1 items
@@ -188,7 +188,7 @@ inspect what is going on and can now run the tests::
$ pytest test_module.py
======= test session starts ========
platform linux -- Python 3.5.2, pytest-3.0.4, py-1.4.31, pluggy-0.4.0
platform linux -- Python 3.5.2, pytest-3.0.6, py-1.4.33, pluggy-0.4.0
rootdir: $REGENDOC_TMPDIR, inifile:
collected 2 items
@@ -257,8 +257,9 @@ the code after the *yield* statement serves as the teardown code.::
print("teardown smtp")
smtp.close()
The ``print`` and ``smtp.close()`` statements will execute when the last test using
the fixture in the module has finished execution, regardless of the exception status of the tests.
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::
@@ -318,8 +319,7 @@ the ``with`` statement ends.
request.addfinalizer(fin)
return smtp # provide the fixture value
The ``fin`` function will execute when the last test using
the fixture in the module has finished execution.
The ``fin`` function will execute when the last test in the module has finished execution.
This method is still fully supported, but ``yield`` is recommended from 2.10 onward because
it is considered simpler and better describes the natural code flow.
@@ -520,7 +520,7 @@ Running the above tests results in the following test IDs being used::
$ pytest --collect-only
======= test session starts ========
platform linux -- Python 3.5.2, pytest-3.0.4, py-1.4.31, pluggy-0.4.0
platform linux -- Python 3.5.2, pytest-3.0.6, py-1.4.33, pluggy-0.4.0
rootdir: $REGENDOC_TMPDIR, inifile:
collected 11 items
<Module 'test_anothersmtp.py'>
@@ -573,7 +573,7 @@ Here we declare an ``app`` fixture which receives the previously defined
$ pytest -v test_appsetup.py
======= test session starts ========
platform linux -- Python 3.5.2, pytest-3.0.4, py-1.4.31, pluggy-0.4.0 -- $PYTHON_PREFIX/bin/python3.5
platform linux -- Python 3.5.2, pytest-3.0.6, py-1.4.33, pluggy-0.4.0 -- $PYTHON_PREFIX/bin/python3.5m
cachedir: .cache
rootdir: $REGENDOC_TMPDIR, inifile:
collecting ... collected 2 items
@@ -642,7 +642,7 @@ Let's run the tests in verbose mode and with looking at the print-output::
$ pytest -v -s test_module.py
======= test session starts ========
platform linux -- Python 3.5.2, pytest-3.0.4, py-1.4.31, pluggy-0.4.0 -- $PYTHON_PREFIX/bin/python3.5
platform linux -- Python 3.5.2, pytest-3.0.6, py-1.4.33, pluggy-0.4.0 -- $PYTHON_PREFIX/bin/python3.5m
cachedir: .cache
rootdir: $REGENDOC_TMPDIR, inifile:
collecting ... collected 8 items
@@ -1002,7 +1002,7 @@ Given the tests file structure is:
@pytest.mark.parametrize('username', ['directly-overridden-username-other'])
def test_username_other(other_username):
assert username == 'other-directly-overridden-username-other'
assert other_username == 'other-directly-overridden-username-other'
In the example above, a fixture value is overridden by the test parameter value. Note that the value of the fixture
can be overridden this way even if the test doesn't use it directly (doesn't mention it in the function prototype).

View File

@@ -97,7 +97,7 @@ sets. pytest-2.3 introduces a decorator for use on the factory itself::
... # use request.param
Here the factory will be invoked twice (with the respective "mysql"
and "pg" values set as ``request.param`` attributes) and and all of
and "pg" values set as ``request.param`` attributes) and all of
the tests requiring "db" will run twice as well. The "mysql" and
"pg" values will also be used for reporting the test-invocation variants.

View File

@@ -26,7 +26,7 @@ Installation::
To check your installation has installed the correct version::
$ pytest --version
This is pytest version 3.0.4, imported from $PYTHON_PREFIX/lib/python3.5/site-packages/pytest.py
This is pytest version 3.0.6, imported from $PYTHON_PREFIX/lib/python3.5/site-packages/pytest.py
.. _`simpletest`:
@@ -46,7 +46,7 @@ That's it. You can execute the test function now::
$ pytest
======= test session starts ========
platform linux -- Python 3.5.2, pytest-3.0.4, py-1.4.31, pluggy-0.4.0
platform linux -- Python 3.5.2, pytest-3.0.6, py-1.4.33, pluggy-0.4.0
rootdir: $REGENDOC_TMPDIR, inifile:
collected 1 items

View File

@@ -16,10 +16,12 @@ Conventions for Python test discovery
* If no arguments are specified then collection starts from :confval:`testpaths`
(if configured) or the current directory. Alternatively, command line arguments
can be used in any combination of directories, file names or node ids.
* recurse into directories, unless they match :confval:`norecursedirs`
* ``test_*.py`` or ``*_test.py`` files, imported by their `test package name`_.
* ``Test`` prefixed test classes (without an ``__init__`` method)
* ``test_`` prefixed test functions or methods are test items
* Recurse into directories, unless they match :confval:`norecursedirs`.
* 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)
For examples of how to customize your test discovery :doc:`example/pythoncollection`.
@@ -125,7 +127,7 @@ required configurations.
The reason for this somewhat evolved importing technique is
that in larger projects multiple test modules might import
from each other and thus deriving a canonical import name helps
to avoid surprises such as a test modules getting imported twice.
to avoid surprises such as a test module getting imported twice.
.. _`virtualenv`: http://pypi.python.org/pypi/virtualenv
@@ -145,7 +147,7 @@ dependencies are isolated from the system Python installation.
If you frequently release code 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
<http://testrun.org/tox/latest/example/pytest.html>`_.
<https://tox.readthedocs.io/en/latest/example/pytest.html>`_.
Tox helps you to setup virtualenv environments with pre-defined
dependencies and then executing a pre-configured test command with
options. It will run tests against the installed package and not

View File

@@ -14,18 +14,18 @@ An example of a simple test:
.. code-block:: python
# content of test_sample.py
def func(x):
def inc(x):
return x + 1
def test_answer():
assert func(3) == 5
assert inc(3) == 5
To execute it::
$ pytest
======= test session starts ========
platform linux -- Python 3.5.2, pytest-3.0.4, py-1.4.31, pluggy-0.4.0
platform linux -- Python 3.5.2, pytest-3.0.6, py-1.4.33, pluggy-0.4.0
rootdir: $REGENDOC_TMPDIR, inifile:
collected 1 items
@@ -35,9 +35,9 @@ To execute it::
_______ test_answer ________
def test_answer():
> assert func(3) == 5
> assert inc(3) == 5
E assert 4 == 5
E + where 4 = func(3)
E + where 4 = inc(3)
test_sample.py:5: AssertionError
======= 1 failed in 0.12 seconds ========

View File

@@ -35,7 +35,7 @@ patch this function before calling into a function which uses it::
assert x == '/abc/.ssh'
Here our test function monkeypatches ``os.path.expanduser`` and
then calls into an function that calls it. After the test function
then calls into a function that calls it. After the test function
finishes the ``os.path.expanduser`` modification will be undone.
example: preventing "requests" from remote operations
@@ -60,7 +60,7 @@ so that any attempts within tests to create http requests will fail.
Be advised that it is not recommended to patch builtin functions such as ``open``,
``compile``, etc., because it might break pytest's internals. If that's
unavoidable, passing ``--tb=native``, ``--assert=plain`` and ``--capture=no`` might
help althought there's no guarantee.
help although there's no guarantee.
Method reference of the monkeypatch fixture

View File

@@ -55,7 +55,7 @@ them in turn::
$ pytest
======= test session starts ========
platform linux -- Python 3.5.2, pytest-3.0.4, py-1.4.31, pluggy-0.4.0
platform linux -- Python 3.5.2, pytest-3.0.6, py-1.4.33, pluggy-0.4.0
rootdir: $REGENDOC_TMPDIR, inifile:
collected 3 items
@@ -103,7 +103,7 @@ Let's run this::
$ pytest
======= test session starts ========
platform linux -- Python 3.5.2, pytest-3.0.4, py-1.4.31, pluggy-0.4.0
platform linux -- Python 3.5.2, pytest-3.0.6, py-1.4.33, pluggy-0.4.0
rootdir: $REGENDOC_TMPDIR, inifile:
collected 3 items

View File

@@ -58,7 +58,7 @@ Here are some examples of projects using ``pytest`` (please send notes via :ref:
* `katcp <https://bitbucket.org/hodgestar/katcp>`_ Telescope communication protocol over Twisted
* `kss plugin timer <http://pypi.python.org/pypi/kss.plugin.timer>`_
* `pyudev <https://pyudev.readthedocs.io/en/latest/tests/plugins.html>`_ a pure Python binding to the Linux library libudev
* `pytest-localserver <https://bitbucket.org/basti/pytest-localserver/>`_ a plugin for pytest that provides a httpserver and smtpserver
* `pytest-localserver <https://bitbucket.org/basti/pytest-localserver/>`_ a plugin for pytest that provides an httpserver and smtpserver
* `pytest-monkeyplus <http://pypi.python.org/pypi/pytest-monkeyplus/>`_ a plugin that extends monkeypatch
These projects help integrate ``pytest`` into other Python frameworks:

View File

@@ -1,8 +1,12 @@
.. _`asserting warnings`:
.. _assertwarnings:
Asserting Warnings
=====================================================
.. _`asserting warnings with the warns function`:
.. _warns:
Asserting warnings with the warns function
@@ -46,6 +50,8 @@ Alternatively, you can examine raised warnings in detail using the
``DeprecationWarning`` and ``PendingDeprecationWarning`` are treated
differently; see :ref:`ensuring_function_triggers`.
.. _`recording warnings`:
.. _recwarn:
Recording warnings
@@ -96,6 +102,8 @@ class of the warning. The ``message`` is the warning itself; calling
``DeprecationWarning`` and ``PendingDeprecationWarning`` are treated
differently; see :ref:`ensuring_function_triggers`.
.. _`ensuring a function triggers a deprecation warning`:
.. _ensuring_function_triggers:
Ensuring a function triggers a deprecation warning

View File

@@ -2,7 +2,7 @@
.. _skipping:
Skip and xfail: dealing with tests that can not succeed
Skip and xfail: dealing with tests that cannot succeed
=====================================================================
If you have test functions that cannot be run on certain platforms
@@ -224,7 +224,7 @@ Running it with the report-on-xfail option gives this output::
example $ pytest -rx xfail_demo.py
======= test session starts ========
platform linux -- Python 3.5.2, pytest-3.0.4, py-1.4.31, pluggy-0.4.0
platform linux -- Python 3.5.2, pytest-3.0.6, py-1.4.33, pluggy-0.4.0
rootdir: $REGENDOC_TMPDIR/example, inifile:
collected 7 items

View File

@@ -11,6 +11,9 @@ Talks and Tutorials
Talks and blog postings
---------------------------------------------
- `Pythonic testing, Igor Starikov (Russian, PyNsk, November 2016)
<https://www.youtube.com/watch?v=_92nfdd5nK8>`_.
- `pytest - Rapid Simple Testing, Florian Bruhin, Swiss Python Summit 2016
<https://www.youtube.com/watch?v=rCBHkQ_LVIs>`_.

View File

@@ -71,7 +71,7 @@ you can ad-hoc distribute your tests by typing::
pytest -d --tx ssh=myhostpopen --rsyncdir mypkg mypkg
This will synchronize your ``mypkg`` package directory
to an remote ssh account and then locally collect tests
to a remote ssh account and then locally collect tests
and send them to remote places for execution.
You can specify multiple ``--rsyncdir`` directories

View File

@@ -29,7 +29,7 @@ Running this would result in a passed test except for the last
$ pytest test_tmpdir.py
======= test session starts ========
platform linux -- Python 3.5.2, pytest-3.0.4, py-1.4.31, pluggy-0.4.0
platform linux -- Python 3.5.2, pytest-3.0.6, py-1.4.33, pluggy-0.4.0
rootdir: $REGENDOC_TMPDIR, inifile:
collected 1 items

View File

@@ -100,7 +100,7 @@ the ``self.db`` values in the traceback::
$ pytest test_unittest_db.py
======= test session starts ========
platform linux -- Python 3.5.2, pytest-3.0.4, py-1.4.31, pluggy-0.4.0
platform linux -- Python 3.5.2, pytest-3.0.6, py-1.4.33, pluggy-0.4.0
rootdir: $REGENDOC_TMPDIR, inifile:
collected 2 items

View File

@@ -16,8 +16,8 @@ You can invoke testing through the Python interpreter from the command line::
python -m pytest [...]
This is equivalent to invoking the command line script ``pytest [...]``
directly.
This is almost equivalent to invoking the command line script ``pytest [...]``
directly, except that python will also add the current directory to ``sys.path``.
Getting help on version, option names, environment variables
--------------------------------------------------------------
@@ -49,7 +49,7 @@ Several test run options::
# will select TestMyClass.test_something
# but not TestMyClass.test_method_simple
pytest test_mod.py::test_func # only run tests that match the "node ID",
# e.g "test_mod.py::test_func" will select
# e.g. "test_mod.py::test_func" will select
# only test_func in test_mod.py
pytest test_mod.py::TestClass::test_method # run a single method in
# a single class
@@ -76,7 +76,7 @@ Examples for modifying traceback printing::
The ``--full-trace`` causes very long traces to be printed on error (longer
than ``--tb=long``). It also ensures that a stack trace is printed on
**KeyboardInterrrupt** (Ctrl+C).
**KeyboardInterrupt** (Ctrl+C).
This is very useful if the tests are taking too long and you interrupt them
with Ctrl+C to find out where the tests are *hanging*. By default no output
will be shown (because KeyboardInterrupt is caught by pytest). By using this

View File

@@ -172,7 +172,7 @@ If a package is installed this way, ``pytest`` will load
.. note::
Make sure to include ``Framework :: Pytest`` in your list of
`PyPI classifiers <https://python-packaging-user-guide.readthedocs.io/en/latest/distributing/#classifiers>`_
`PyPI classifiers <https://python-packaging-user-guide.readthedocs.io/distributing/#classifiers>`_
to make it easy for users to find your plugin.
@@ -250,8 +250,8 @@ which will import the specified module as a ``pytest`` plugin.
Plugins imported like this will automatically be marked to require
assertion rewriting using the :func:`pytest.register_assert_rewrite`
mechanism. However for this to have any effect the module must not be
imported already, it it was already imported at the time the
``pytest_plugins`` statement is processed a warning will result and
imported already; if it was already imported at the time the
``pytest_plugins`` statement is processed, a warning will result and
assertions inside the plugin will not be re-written. To fix this you
can either call :func:`pytest.register_assert_rewrite` yourself before
the module is imported, or you can arrange the code to delay the

View File

@@ -1,20 +0,0 @@
#!/bin/bash
# this assumes plugins are installed as sister directories
set -e
cd ../pytest-pep8
pytest
cd ../pytest-instafail
pytest
cd ../pytest-cache
pytest
cd ../pytest-xprocess
pytest
#cd ../pytest-cov
#pytest
cd ../pytest-capturelog
pytest
cd ../pytest-xdist
pytest

View File

@@ -1,3 +0,0 @@
sphinx==1.2.3
regendoc
pyyaml

View File

@@ -1,8 +0,0 @@
#!/usr/bin/env python
if __name__ == "__main__":
import subprocess
import sys
subprocess.call([sys.executable, "-m", "tox",
"-i", "ALL=https://devpi.net/hpk/dev/",
"--develop"] + sys.argv[1:])

8
scripts/call-tox.bat Normal file
View File

@@ -0,0 +1,8 @@
REM skip "coveralls" run in PRs or forks
if "%TOXENV%" == "coveralls" (
if not defined COVERALLS_REPO_TOKEN (
echo skipping coveralls run because COVERALLS_REPO_TOKEN is not defined
exit /b 0
)
)
C:\Python35\python -m tox

21
scripts/check-manifest.py Normal file
View File

@@ -0,0 +1,21 @@
"""
Script used by tox.ini to check the manifest file if we are under version control, or skip the
check altogether if not.
"check-manifest" will needs a vcs to work, which is not available when testing the package
instead of the source code (with ``devpi test`` for example).
"""
from __future__ import print_function
import os
import subprocess
import sys
if os.path.isdir('.git'):
sys.exit(subprocess.call('check-manifest', shell=True))
else:
print('No .git directory found, skipping checking the manifest file')
sys.exit(0)

6
scripts/install-pypy.bat Normal file
View File

@@ -0,0 +1,6 @@
REM install pypy using choco
REM redirect to a file because choco install python.pypy is too noisy. If the command fails, write output to console
choco install python.pypy > pypy-inst.log 2>&1 || (type pypy-inst.log & exit /b 1)
set PATH=C:\tools\pypy\pypy;%PATH% # so tox can find pypy
echo PyPy installed
pypy --version

View File

@@ -9,5 +9,8 @@ upload-dir = doc/en/build/html
[bdist_wheel]
universal = 1
[metadata]
license_file = LICENSE
[devpi:upload]
formats = sdist.tgz,bdist_wheel

View File

@@ -48,7 +48,7 @@ def has_environment_marker_support():
def main():
install_requires = ['py>=1.4.29'] # pluggy is vendored in _pytest.vendored_packages
install_requires = ['py>=1.4.29', 'setuptools'] # pluggy is vendored in _pytest.vendored_packages
extras_require = {}
if has_environment_marker_support():
extras_require[':python_version=="2.6"'] = ['argparse']
@@ -68,10 +68,10 @@ def main():
license='MIT license',
platforms=['unix', 'linux', 'osx', 'cygwin', 'win32'],
author='Holger Krekel, Bruno Oliveira, Ronny Pfannschmidt, Floris Bruynooghe, Brianna Laugher, Florian Bruhin and others',
author_email='holger at merlinux.eu',
entry_points={'console_scripts':
['pytest=pytest:main', 'py.test=pytest:main']},
classifiers=classifiers,
keywords="test unittest",
cmdclass={'test': PyTest},
# the following should be enabled for release
install_requires=install_requires,

View File

@@ -24,6 +24,7 @@ def test_code_with_class():
pass
pytest.raises(TypeError, "_pytest._code.Code(A)")
if True:
def x():
pass
@@ -68,8 +69,10 @@ def test_code_from_func():
def test_unicode_handling():
value = py.builtin._totext('\xc4\x85\xc4\x87\n', 'utf-8').encode('utf8')
def f():
raise Exception(value)
excinfo = pytest.raises(Exception, f)
str(excinfo)
if sys.version_info[0] < 3:
@@ -79,8 +82,10 @@ def test_unicode_handling():
@pytest.mark.skipif(sys.version_info[0] >= 3, reason='python 2 only issue')
def test_unicode_handling_syntax_error():
value = py.builtin._totext('\xc4\x85\xc4\x87\n', 'utf-8').encode('utf8')
def f():
raise SyntaxError('invalid syntax', (None, 1, 3, value))
excinfo = pytest.raises(Exception, f)
str(excinfo)
if sys.version_info[0] < 3:

View File

@@ -56,13 +56,15 @@ def test_excinfo_simple():
def test_excinfo_getstatement():
def g():
raise ValueError
def f():
g()
try:
f()
except ValueError:
excinfo = _pytest._code.ExceptionInfo()
linenumbers = [_pytest._code.getrawcode(f).co_firstlineno - 1 + 3,
linenumbers = [_pytest._code.getrawcode(f).co_firstlineno - 1 + 4,
_pytest._code.getrawcode(f).co_firstlineno - 1 + 1,
_pytest._code.getrawcode(g).co_firstlineno - 1 + 1, ]
l = list(excinfo.traceback)
@@ -168,11 +170,13 @@ class TestTraceback_f_g_h:
#
raise ValueError
#
def g():
#
__tracebackhide__ = tracebackhide
f()
#
def h():
#
g()
@@ -214,15 +218,18 @@ class TestTraceback_f_g_h:
def test_traceback_no_recursion_index(self):
def do_stuff():
raise RuntimeError
def reraise_me():
import sys
exc, val, tb = sys.exc_info()
py.builtin._reraise(exc, val, tb)
def f(n):
try:
do_stuff()
except:
reraise_me()
excinfo = pytest.raises(RuntimeError, f, 8)
traceback = excinfo.traceback
recindex = traceback.recursionindex()
@@ -245,17 +252,18 @@ class TestTraceback_f_g_h:
excinfo = pytest.raises(ValueError, fail)
assert excinfo.traceback.recursionindex() is None
def test_traceback_getcrashentry(self):
def i():
__tracebackhide__ = True
raise ValueError
def h():
i()
def g():
__tracebackhide__ = True
h()
def f():
g()
@@ -271,6 +279,7 @@ class TestTraceback_f_g_h:
def g():
__tracebackhide__ = True
raise ValueError
def f():
__tracebackhide__ = True
g()
@@ -465,11 +474,13 @@ raise ValueError()
class FakeCode(object):
class raw:
co_filename = '?'
path = '?'
firstlineno = 5
def fullsource(self):
return None
fullsource = property(fullsource)
class FakeFrame(object):
@@ -491,17 +502,21 @@ raise ValueError()
class FakeExcinfo(_pytest._code.ExceptionInfo):
typename = "Foo"
value = Exception()
def __init__(self):
pass
def exconly(self, tryshort):
return "EXC"
def errisinstance(self, cls):
return False
excinfo = FakeExcinfo()
class FakeRawTB(object):
tb_next = None
tb = FakeRawTB()
excinfo.traceback = Traceback(tb)
@@ -719,8 +734,10 @@ raise ValueError()
excinfo = pytest.raises(ValueError, mod.entry)
p = FormattedExcinfo()
def raiseos():
raise OSError(2)
monkeypatch.setattr(py.std.os, 'getcwd', raiseos)
assert p._makepath(__file__) == __file__
p.repr_traceback(excinfo)
@@ -789,9 +806,11 @@ raise ValueError()
def test_reprexcinfo_unicode(self):
from _pytest._code.code import TerminalRepr
class MyRepr(TerminalRepr):
def toterminal(self, tw):
tw.line(py.builtin._totext("я", "utf-8"))
x = py.builtin._totext(MyRepr())
assert x == py.builtin._totext("я", "utf-8")

View File

@@ -1,5 +1,5 @@
# encoding: utf-8
import sys
import pytest
import doctest
@@ -9,6 +9,7 @@ from decimal import Decimal
from fractions import Fraction
inf, nan = float('inf'), float('nan')
class MyDocTestRunner(doctest.DocTestRunner):
def __init__(self):
@@ -22,12 +23,17 @@ class MyDocTestRunner(doctest.DocTestRunner):
class TestApprox:
def test_repr_string(self):
# Just make sure the Unicode handling doesn't raise any exceptions.
print(approx(1.0))
print(approx([1.0, 2.0, 3.0]))
print(approx(inf))
print(approx(1.0, rel=nan))
print(approx(1.0, rel=inf))
# for some reason in Python 2.6 it is not displaying the tolerance representation correctly
plus_minus = u'\u00b1' if sys.version_info[0] > 2 else u'+-'
tol1, tol2, infr = '1.0e-06', '2.0e-06', 'inf'
if sys.version_info[:2] == (2, 6):
tol1, tol2, infr = '???', '???', '???'
assert repr(approx(1.0)) == '1.0 {pm} {tol1}'.format(pm=plus_minus, tol1=tol1)
assert repr(approx([1.0, 2.0])) == '1.0 {pm} {tol1}, 2.0 {pm} {tol2}'.format(pm=plus_minus, tol1=tol1, tol2=tol2)
assert repr(approx(inf)) == 'inf'
assert repr(approx(1.0, rel=nan)) == '1.0 {pm} ???'.format(pm=plus_minus)
assert repr(approx(1.0, rel=inf)) == '1.0 {pm} {infr}'.format(pm=plus_minus, infr=infr)
assert repr(approx(1.0j, rel=inf)) == '1j'
def test_operator_overloading(self):
assert 1 == approx(1, rel=1e-6, abs=1e-12)
@@ -284,3 +290,23 @@ class TestApprox:
runner = MyDocTestRunner()
runner.run(test)
def test_unicode_plus_minus(self, testdir):
"""
Comparing approx instances inside lists should not produce an error in the detailed diff.
Integration test for issue #2111.
"""
testdir.makepyfile("""
import pytest
def test_foo():
assert [3] == [pytest.approx(4)]
""")
expected = '4.0e-06'
# for some reason in Python 2.6 it is not displaying the tolerance representation correctly
if sys.version_info[:2] == (2, 6):
expected = '???'
result = testdir.runpytest()
result.stdout.fnmatch_lines([
'*At index 0 diff: 3 != 4 * {0}'.format(expected),
'=* 1 failed in *=',
])

View File

@@ -383,10 +383,13 @@ class TestFunction:
config = testdir.parseconfigure()
session = testdir.Session(config)
session._fixturemanager = FixtureManager(session)
def func1():
pass
def func2():
pass
f1 = pytest.Function(name="name", parent=session, config=config,
args=(1,), callobj=func1)
assert f1 == f1
@@ -547,12 +550,15 @@ class TestFunction:
def test_pyfunc_call(self, testdir):
item = testdir.getitem("def test_func(): raise ValueError")
config = item.config
class MyPlugin1:
def pytest_pyfunc_call(self, pyfuncitem):
raise ValueError
class MyPlugin2:
def pytest_pyfunc_call(self, pyfuncitem):
return True
config.pluginmanager.register(MyPlugin1())
config.pluginmanager.register(MyPlugin2())
config.hook.pytest_runtest_setup(item=item)

View File

@@ -10,15 +10,20 @@ from _pytest import fixtures
def test_getfuncargnames():
def f(): pass
assert not fixtures.getfuncargnames(f)
def g(arg): pass
assert fixtures.getfuncargnames(g) == ('arg',)
def h(arg1, arg2="hello"): pass
assert fixtures.getfuncargnames(h) == ('arg1',)
def h(arg1, arg2, arg3="hello"): pass
assert fixtures.getfuncargnames(h) == ('arg1', 'arg2')
class A:
def f(self, arg1, arg2="hello"):
pass
assert fixtures.getfuncargnames(A().f) == ('arg1',)
if sys.version_info < (3,0):
assert fixtures.getfuncargnames(A.f) == ('arg1',)
@@ -869,8 +874,10 @@ class TestRequestCachedSetup:
item1 = testdir.getitem("def test_func(): pass")
req1 = fixtures.FixtureRequest(item1)
l = ["hello", "world"]
def setup():
return l.pop()
ret1 = req1.cached_setup(setup, extrakey=1)
ret2 = req1.cached_setup(setup, extrakey=2)
assert ret2 == "hello"
@@ -884,10 +891,13 @@ class TestRequestCachedSetup:
item1 = testdir.getitem("def test_func(): pass")
req1 = fixtures.FixtureRequest(item1)
l = []
def setup():
l.append("setup")
def teardown(val):
l.append("teardown")
req1.cached_setup(setup, teardown, scope="function")
assert l == ['setup']
# artificial call of finalizer

View File

@@ -63,10 +63,12 @@ class TestOEJSKITSpecials:
def test_wrapped_getfslineno():
def func():
pass
def wrap(f):
func.__wrapped__ = f
func.patchings = ["qwe"]
return func
@wrap
def wrapped_func(x, y, z):
pass
@@ -77,28 +79,36 @@ def test_wrapped_getfslineno():
class TestMockDecoration:
def test_wrapped_getfuncargnames(self):
from _pytest.compat import getfuncargnames
def wrap(f):
def func():
pass
func.__wrapped__ = f
return func
@wrap
def f(x):
pass
l = getfuncargnames(f)
assert l == ("x",)
def test_wrapped_getfuncargnames_patching(self):
from _pytest.compat import getfuncargnames
def wrap(f):
def func():
pass
func.__wrapped__ = f
func.patchings = ["qwe"]
return func
@wrap
def f(x, y, z):
pass
l = getfuncargnames(f)
assert l == ("y", "z")

View File

@@ -20,8 +20,10 @@ class TestMetafunc:
# initiliazation
class FixtureInfo:
name2fixturedefs = None
def __init__(self, names):
self.names_closure = names
names = fixtures.getfuncargnames(func)
fixtureinfo = FixtureInfo(names)
return python.Metafunc(func, fixtureinfo, None)
@@ -65,7 +67,9 @@ class TestMetafunc:
def test_addcall_param(self):
def func(arg1): pass
metafunc = self.Metafunc(func)
class obj: pass
metafunc.addcall(param=obj)
metafunc.addcall(param=obj)
metafunc.addcall(param=1)
@@ -76,8 +80,11 @@ class TestMetafunc:
def test_addcall_funcargs(self):
def func(x): pass
metafunc = self.Metafunc(func)
class obj: pass
metafunc.addcall(funcargs={"x": 2})
metafunc.addcall(funcargs={"x": 3})
pytest.raises(pytest.fail.Exception, "metafunc.addcall({'xyz': 0})")
@@ -142,8 +149,10 @@ class TestMetafunc:
def test_parametrize_with_userobjects(self):
def func(x, y): pass
metafunc = self.Metafunc(func)
class A:
pass
metafunc.parametrize("x", [A(), A()])
metafunc.parametrize("y", list("ab"))
assert metafunc._calls[0].id == "x0-a"
@@ -254,6 +263,7 @@ class TestMetafunc:
@pytest.mark.issue351
def test_idmaker_idfn(self):
from _pytest.python import idmaker
def ids(val):
if isinstance(val, Exception):
return repr(val)
@@ -270,6 +280,7 @@ class TestMetafunc:
@pytest.mark.issue351
def test_idmaker_idfn_unique_names(self):
from _pytest.python import idmaker
def ids(val):
return 'a'
@@ -285,6 +296,7 @@ class TestMetafunc:
@pytest.mark.issue351
def test_idmaker_idfn_exception(self):
from _pytest.python import idmaker
def ids(val):
raise Exception("bad code")

View File

@@ -12,12 +12,15 @@ PY3 = sys.version_info >= (3, 0)
@pytest.fixture
def mock_config():
class Config(object):
verbose = False
def getoption(self, name):
if name == 'verbose':
return self.verbose
raise KeyError('Not mocked out: %s' % name)
return Config()
@@ -55,6 +58,23 @@ class TestImportHookInstallation:
assert 0
result.stdout.fnmatch_lines([expected])
def test_rewrite_assertions_pytester_plugin(self, testdir):
"""
Assertions in the pytester plugin must also benefit from assertion
rewriting (#1920).
"""
testdir.makepyfile("""
pytest_plugins = ['pytester']
def test_dummy_failure(testdir): # how meta!
testdir.makepyfile('def test(): assert 0')
r = testdir.inline_run()
r.assertoutcome(passed=1)
""")
result = testdir.runpytest_subprocess()
result.stdout.fnmatch_lines([
'*assert 1 == 0*',
])
@pytest.mark.parametrize('mode', ['plain', 'rewrite'])
def test_pytest_plugins_rewrite(self, testdir, mode):
contents = {

View File

@@ -1,7 +1,10 @@
import glob
import os
import py_compile
import stat
import sys
import zipfile
import py
import pytest
@@ -104,20 +107,29 @@ class TestAssertionRewrite:
def f():
assert False
assert getmsg(f) == "assert False"
def f():
f = False
assert f
assert getmsg(f) == "assert False"
def f():
assert a_global # noqa
assert getmsg(f, {"a_global" : False}) == "assert False"
def f():
assert sys == 42
assert getmsg(f, {"sys" : sys}) == "assert sys == 42"
def f():
assert cls == 42 # noqa
class X(object):
pass
assert getmsg(f, {"cls" : X}) == "assert cls == 42"
def test_assert_already_has_message(self):
@@ -190,78 +202,110 @@ class TestAssertionRewrite:
def f():
f = g = False
assert f and g
assert getmsg(f) == "assert (False)"
def f():
f = True
g = False
assert f and g
assert getmsg(f) == "assert (True and False)"
def f():
f = False
g = True
assert f and g
assert getmsg(f) == "assert (False)"
def f():
f = g = False
assert f or g
assert getmsg(f) == "assert (False or False)"
def f():
f = g = False
assert not f and not g
getmsg(f, must_pass=True)
def x():
return False
def f():
assert x() and x()
assert getmsg(f, {"x" : x}) == """assert (False)
+ where False = x()"""
def f():
assert False or x()
assert getmsg(f, {"x" : x}) == """assert (False or False)
+ where False = x()"""
def f():
assert 1 in {} and 2 in {}
assert getmsg(f) == "assert (1 in {})"
def f():
x = 1
y = 2
assert x in {1 : None} and y in {}
assert getmsg(f) == "assert (1 in {1: None} and 2 in {})"
def f():
f = True
g = False
assert f or g
getmsg(f, must_pass=True)
def f():
f = g = h = lambda: True
assert f() and g() and h()
getmsg(f, must_pass=True)
def test_short_circut_evaluation(self):
def f():
assert True or explode # noqa
getmsg(f, must_pass=True)
def f():
x = 1
assert x == 1 or x == 2
getmsg(f, must_pass=True)
def test_unary_op(self):
def f():
x = True
assert not x
assert getmsg(f) == "assert not True"
def f():
x = 0
assert ~x + 1
assert getmsg(f) == "assert (~0 + 1)"
def f():
x = 3
assert -x + x
assert getmsg(f) == "assert (-3 + 3)"
def f():
x = 0
assert +x + x
assert getmsg(f) == "assert (+0 + 0)"
def test_binary_op(self):
@@ -269,7 +313,9 @@ class TestAssertionRewrite:
x = 1
y = -1
assert x + y
assert getmsg(f) == "assert (1 + -1)"
def f():
assert not 5 % 4
assert getmsg(f) == "assert not (5 % 4)"
@@ -277,7 +323,9 @@ class TestAssertionRewrite:
def test_boolop_percent(self):
def f():
assert 3 % 2 and False
assert getmsg(f) == "assert ((3 % 2) and False)"
def f():
assert False or 4 % 2
assert getmsg(f) == "assert (False or (4 % 2))"
@@ -298,113 +346,159 @@ class TestAssertionRewrite:
def test_call(self):
def g(a=42, *args, **kwargs):
return False
ns = {"g" : g}
def f():
assert g()
assert getmsg(f, ns) == """assert False
+ where False = g()"""
def f():
assert g(1)
assert getmsg(f, ns) == """assert False
+ where False = g(1)"""
def f():
assert g(1, 2)
assert getmsg(f, ns) == """assert False
+ where False = g(1, 2)"""
def f():
assert g(1, g=42)
assert getmsg(f, ns) == """assert False
+ where False = g(1, g=42)"""
def f():
assert g(1, 3, g=23)
assert getmsg(f, ns) == """assert False
+ where False = g(1, 3, g=23)"""
def f():
seq = [1, 2, 3]
assert g(*seq)
assert getmsg(f, ns) == """assert False
+ where False = g(*[1, 2, 3])"""
def f():
x = "a"
assert g(**{x : 2})
assert getmsg(f, ns) == """assert False
+ where False = g(**{'a': 2})"""
def test_attribute(self):
class X(object):
g = 3
ns = {"x" : X}
def f():
assert not x.g # noqa
assert getmsg(f, ns) == """assert not 3
+ where 3 = x.g"""
def f():
x.a = False # noqa
assert x.a # noqa
assert getmsg(f, ns) == """assert False
+ where False = x.a"""
def test_comparisons(self):
def f():
a, b = range(2)
assert b < a
assert getmsg(f) == """assert 1 < 0"""
def f():
a, b, c = range(3)
assert a > b > c
assert getmsg(f) == """assert 0 > 1"""
def f():
a, b, c = range(3)
assert a < b > c
assert getmsg(f) == """assert 1 > 2"""
def f():
a, b, c = range(3)
assert a < b <= c
getmsg(f, must_pass=True)
def f():
a, b, c = range(3)
assert a < b
assert b < c
getmsg(f, must_pass=True)
def test_len(self):
def f():
l = list(range(10))
assert len(l) == 11
assert getmsg(f).startswith("""assert 10 == 11
+ where 10 = len([""")
def test_custom_reprcompare(self, monkeypatch):
def my_reprcompare(op, left, right):
return "42"
monkeypatch.setattr(util, "_reprcompare", my_reprcompare)
def f():
assert 42 < 3
assert getmsg(f) == "assert 42"
def my_reprcompare(op, left, right):
return "%s %s %s" % (left, op, right)
monkeypatch.setattr(util, "_reprcompare", my_reprcompare)
def f():
assert 1 < 3 < 5 <= 4 < 7
assert getmsg(f) == "assert 5 <= 4"
def test_assert_raising_nonzero_in_comparison(self):
def f():
class A(object):
def __nonzero__(self):
raise ValueError(42)
def __lt__(self, other):
return A()
def __repr__(self):
return "<MY42 object>"
def myany(x):
return False
assert myany(A() < 0)
assert "<MY42 object> < 0" in getmsg(f)
def test_formatchar(self):
def f():
assert "%test" == "test"
assert getmsg(f).startswith("assert '%test' == 'test'")
def test_custom_repr(self):
@@ -414,8 +508,10 @@ class TestAssertionRewrite:
def __repr__(self):
return "\n{ \n~ \n}"
f = Foo()
assert 0 == f.a
assert r"where 1 = \n{ \n~ \n}.a" in util._format_lines([getmsg(f)])[0]
@@ -480,6 +576,31 @@ def test_rewritten():
monkeypatch.setenv("PYTHONDONTWRITEBYTECODE", "1")
assert testdir.runpytest_subprocess().ret == 0
def test_orphaned_pyc_file(self, testdir):
if sys.version_info < (3, 0) and hasattr(sys, 'pypy_version_info'):
pytest.skip("pypy2 doesn't run orphaned pyc files")
testdir.makepyfile("""
import orphan
def test_it():
assert orphan.value == 17
""")
testdir.makepyfile(orphan="""
value = 17
""")
py_compile.compile("orphan.py")
os.remove("orphan.py")
# Python 3 puts the .pyc files in a __pycache__ directory, and will
# not import from there without source. It will import a .pyc from
# the source location though.
if not os.path.exists("orphan.pyc"):
pycs = glob.glob("__pycache__/orphan.*.pyc")
assert len(pycs) == 1
os.rename(pycs[0], "orphan.pyc")
assert testdir.runpytest().ret == 0
@pytest.mark.skipif('"__pypy__" in sys.modules')
def test_pyc_vs_pyo(self, testdir, monkeypatch):
testdir.makepyfile("""
@@ -527,8 +648,10 @@ def test_rewritten():
def test_rewrite_warning(self, pytestconfig, monkeypatch):
hook = AssertionRewritingHook(pytestconfig)
warnings = []
def mywarn(code, msg):
warnings.append((code, msg))
monkeypatch.setattr(hook.config, 'warn', mywarn)
hook.mark_rewrite('_pytest')
assert '_pytest' in warnings[0][1]
@@ -559,6 +682,35 @@ def test_rewritten():
hook.mark_rewrite('test_remember_rewritten_modules')
assert warnings == []
def test_rewrite_warning_using_pytest_plugins(self, testdir):
testdir.makepyfile(**{
'conftest.py': "pytest_plugins = ['core', 'gui', 'sci']",
'core.py': "",
'gui.py': "pytest_plugins = ['core', 'sci']",
'sci.py': "pytest_plugins = ['core']",
'test_rewrite_warning_pytest_plugins.py': "def test(): pass",
})
testdir.chdir()
result = testdir.runpytest_subprocess()
result.stdout.fnmatch_lines(['*= 1 passed in *=*'])
assert 'pytest-warning summary' not in result.stdout.str()
def test_rewrite_warning_using_pytest_plugins_env_var(self, testdir, monkeypatch):
monkeypatch.setenv('PYTEST_PLUGINS', 'plugin')
testdir.makepyfile(**{
'plugin.py': "",
'test_rewrite_warning_using_pytest_plugins_env_var.py': """
import plugin
pytest_plugins = ['plugin']
def test():
pass
""",
})
testdir.chdir()
result = testdir.runpytest_subprocess()
result.stdout.fnmatch_lines(['*= 1 passed in *=*'])
assert 'pytest-warning summary' not in result.stdout.str()
class TestAssertionRewriteHookDetails(object):
def test_loader_is_package_false_for_module(self, testdir):
@@ -642,10 +794,12 @@ class TestAssertionRewriteHookDetails(object):
source_path = tmpdir.ensure("source.py")
pycpath = tmpdir.join("pyc").strpath
assert _write_pyc(state, [1], source_path.stat(), pycpath)
def open(*args):
e = IOError()
e.errno = 10
raise e
monkeypatch.setattr(b, "open", open)
assert not _write_pyc(state, [1], source_path.stat(), pycpath)

View File

@@ -150,11 +150,13 @@ class TestCollectFS:
class TestCollectPluginHookRelay:
def test_pytest_collect_file(self, testdir):
wascalled = []
class Plugin:
def pytest_collect_file(self, path, parent):
if not path.basename.startswith("."):
# Ignore hidden files, e.g. .testmondata.
wascalled.append(path)
testdir.makefile(".abc", "xyz")
pytest.main([testdir.tmpdir], plugins=[Plugin()])
assert len(wascalled) == 1
@@ -162,15 +164,18 @@ class TestCollectPluginHookRelay:
def test_pytest_collect_directory(self, testdir):
wascalled = []
class Plugin:
def pytest_collect_directory(self, path, parent):
wascalled.append(path.basename)
testdir.mkdir("hello")
testdir.mkdir("world")
pytest.main(testdir.tmpdir, plugins=[Plugin()])
assert "hello" in wascalled
assert "world" in wascalled
class TestPrunetraceback:
def test_custom_repr_failure(self, testdir):

50
testing/test_compat.py Normal file
View File

@@ -0,0 +1,50 @@
import sys
import pytest
from _pytest.compat import is_generator
def test_is_generator():
def zap():
yield
def foo():
pass
assert is_generator(zap)
assert not is_generator(foo)
@pytest.mark.skipif(sys.version_info < (3, 4), reason='asyncio available in Python 3.4+')
def test_is_generator_asyncio(testdir):
testdir.makepyfile("""
from _pytest.compat import is_generator
import asyncio
@asyncio.coroutine
def baz():
yield from [1,2,3]
def test_is_generator_asyncio():
assert not is_generator(baz)
""")
# avoid importing asyncio into pytest's own process, which in turn imports logging (#8)
result = testdir.runpytest_subprocess()
result.stdout.fnmatch_lines(['*1 passed*'])
@pytest.mark.skipif(sys.version_info < (3, 5), reason='async syntax available in Python 3.5+')
def test_is_generator_async_syntax(testdir):
testdir.makepyfile("""
from _pytest.compat import is_generator
def test_is_generator_py35():
async def foo():
await foo()
async def bar():
pass
assert not is_generator(foo)
assert not is_generator(bar)
""")
result = testdir.runpytest()
result.stdout.fnmatch_lines(['*1 passed*'])

View File

@@ -83,7 +83,7 @@ class TestParseIni:
""")
result = testdir.inline_run("--confcutdir=.")
assert result.ret == 0
class TestConfigCmdlineParsing:
def test_parsing_again_fails(self, testdir):
config = testdir.parseconfig()
@@ -294,6 +294,15 @@ class TestConfigAPI:
assert len(l) == 2
assert l == ["456", "123"]
def test_confcutdir_check_isdir(self, testdir):
"""Give an error if --confcutdir is not a valid directory (#2078)"""
with pytest.raises(pytest.UsageError):
testdir.parseconfig('--confcutdir', testdir.tmpdir.join('file').ensure(file=1))
with pytest.raises(pytest.UsageError):
testdir.parseconfig('--confcutdir', testdir.tmpdir.join('inexistant'))
config = testdir.parseconfig('--confcutdir', testdir.tmpdir.join('dir').ensure(dir=1))
assert config.getoption('confcutdir') == str(testdir.tmpdir.join('dir'))
class TestConfigFromdictargs:
def test_basic_behavior(self):
@@ -373,23 +382,31 @@ def test_options_on_small_file_do_not_blow_up(testdir):
['--traceconfig'], ['-v'], ['-v', '-v']):
runfiletest(opts + [path])
def test_preparse_ordering_with_setuptools(testdir, monkeypatch):
pkg_resources = pytest.importorskip("pkg_resources")
def my_iter(name):
assert name == "pytest11"
class Dist:
project_name = 'spam'
version = '1.0'
def _get_metadata(self, name):
return ['foo.txt,sha256=abc,123']
class EntryPoint:
name = "mytestplugin"
dist = Dist()
def load(self):
class PseudoPlugin:
x = 42
return PseudoPlugin()
return iter([EntryPoint()])
monkeypatch.setattr(pkg_resources, 'iter_entry_points', my_iter)
testdir.makeconftest("""
pytest_plugins = "mytestplugin",
@@ -402,18 +419,24 @@ def test_preparse_ordering_with_setuptools(testdir, monkeypatch):
def test_setuptools_importerror_issue1479(testdir, monkeypatch):
pkg_resources = pytest.importorskip("pkg_resources")
def my_iter(name):
assert name == "pytest11"
class Dist:
project_name = 'spam'
version = '1.0'
def _get_metadata(self, name):
return ['foo.txt,sha256=abc,123']
class EntryPoint:
name = "mytestplugin"
dist = Dist()
def load(self):
raise ImportError("Don't hide me!")
return iter([EntryPoint()])
monkeypatch.setattr(pkg_resources, 'iter_entry_points', my_iter)
@@ -423,19 +446,26 @@ def test_setuptools_importerror_issue1479(testdir, monkeypatch):
def test_plugin_preparse_prevents_setuptools_loading(testdir, monkeypatch):
pkg_resources = pytest.importorskip("pkg_resources")
def my_iter(name):
assert name == "pytest11"
class Dist:
project_name = 'spam'
version = '1.0'
def _get_metadata(self, name):
return ['foo.txt,sha256=abc,123']
class EntryPoint:
name = "mytestplugin"
dist = Dist()
def load(self):
assert 0, "should not arrive here"
return iter([EntryPoint()])
monkeypatch.setattr(pkg_resources, 'iter_entry_points', my_iter)
config = testdir.parseconfig("-p", "no:mytestplugin")
plugin = config.pluginmanager.getplugin("mytestplugin")
@@ -497,15 +527,40 @@ def test_toolongargs_issue224(testdir):
result = testdir.runpytest("-m", "hello" * 500)
assert result.ret == EXIT_NOTESTSCOLLECTED
def test_config_in_subdirectory_colon_command_line_issue2148(testdir):
conftest_source = '''
def pytest_addoption(parser):
parser.addini('foo', 'foo')
'''
testdir.makefile('.ini', **{
'pytest': '[pytest]\nfoo = root',
'subdir/pytest': '[pytest]\nfoo = subdir',
})
testdir.makepyfile(**{
'conftest': conftest_source,
'subdir/conftest': conftest_source,
'subdir/test_foo': '''
def test_foo(pytestconfig):
assert pytestconfig.getini('foo') == 'subdir'
'''})
result = testdir.runpytest('subdir/test_foo.py::test_foo')
assert result.ret == 0
def test_notify_exception(testdir, capfd):
config = testdir.parseconfig()
excinfo = pytest.raises(ValueError, "raise ValueError(1)")
config.notify_exception(excinfo)
out, err = capfd.readouterr()
assert "ValueError" in err
class A:
def pytest_internalerror(self, excrepr):
return True
config.pluginmanager.register(A())
config.notify_exception(excinfo)
out, err = capfd.readouterr()
@@ -515,9 +570,11 @@ def test_notify_exception(testdir, capfd):
def test_load_initial_conftest_last_ordering(testdir):
from _pytest.config import get_config
pm = get_config().pluginmanager
class My:
def pytest_load_initial_conftests(self):
pass
m = My()
pm.register(m)
hc = pm.hook.pytest_load_initial_conftests
@@ -530,6 +587,21 @@ def test_load_initial_conftest_last_ordering(testdir):
assert [x.function.__module__ for x in l] == expected
def test_get_plugin_specs_as_list():
from _pytest.config import _get_plugin_specs_as_list
with pytest.raises(pytest.UsageError):
_get_plugin_specs_as_list(set(['foo']))
with pytest.raises(pytest.UsageError):
_get_plugin_specs_as_list(dict())
assert _get_plugin_specs_as_list(None) == []
assert _get_plugin_specs_as_list('') == []
assert _get_plugin_specs_as_list('foo') == ['foo']
assert _get_plugin_specs_as_list('foo,bar') == ['foo', 'bar']
assert _get_plugin_specs_as_list(['foo', 'bar']) == ['foo', 'bar']
assert _get_plugin_specs_as_list(('foo', 'bar')) == ['foo', 'bar']
class TestWarning:
def test_warn_config(self, testdir):
testdir.makeconftest("""
@@ -698,6 +770,14 @@ class TestOverrideIniArgs:
"ini3:True",
"ini4:False"])
def test_override_ini_usage_error_bad_style(self, testdir):
testdir.makeini("""
[pytest]
xdist_strict=False
""")
result = testdir.runpytest("--override-ini", 'xdist_strict True', "-s")
result.stderr.fnmatch_lines(["*ERROR* *expects option=value*"])
def test_with_arg_outside_cwd_without_inifile(self, tmpdir, monkeypatch):
monkeypatch.chdir(str(tmpdir))
a = tmpdir.mkdir("a")

View File

@@ -200,8 +200,10 @@ def test_conftest_import_order(testdir, monkeypatch):
sub = testdir.mkdir("sub")
ct2 = sub.join("conftest.py")
ct2.write("")
def impct(p):
return p
conftest = PytestPluginManager()
conftest._confcutdir = testdir.tmpdir
monkeypatch.setattr(conftest, '_importconftest', impct)
@@ -421,3 +423,28 @@ def test_conftest_exception_handling(testdir):
res = testdir.runpytest()
assert res.ret == 4
assert 'raise ValueError()' in [line.strip() for line in res.errlines]
def test_hook_proxy(testdir):
"""Session's gethookproxy() would cache conftests incorrectly (#2016).
It was decided to remove the cache altogether.
"""
testdir.makepyfile(**{
'root/demo-0/test_foo1.py': "def test1(): pass",
'root/demo-a/test_foo2.py': "def test1(): pass",
'root/demo-a/conftest.py': """
def pytest_ignore_collect(path, config):
return True
""",
'root/demo-b/test_foo3.py': "def test1(): pass",
'root/demo-c/test_foo4.py': "def test1(): pass",
})
result = testdir.runpytest()
result.stdout.fnmatch_lines([
'*test_foo1.py*',
'*test_foo3.py*',
'*test_foo4.py*',
'*3 passed*',
])

View File

@@ -1,9 +1,11 @@
# encoding: utf-8
import sys
import _pytest._code
from _pytest.compat import MODULE_NOT_FOUND_ERROR
from _pytest.doctest import DoctestItem, DoctestModule, DoctestTextfile
import pytest
class TestDoctests:
def test_collect_testtextfile(self, testdir):
@@ -211,8 +213,8 @@ class TestDoctests:
# doctest is never executed because of error during hello.py collection
result.stdout.fnmatch_lines([
"*>>> import asdals*",
"*UNEXPECTED*ImportError*",
"ImportError: No module named *asdal*",
"*UNEXPECTED*{e}*".format(e=MODULE_NOT_FOUND_ERROR),
"{e}: No module named *asdal*".format(e=MODULE_NOT_FOUND_ERROR),
])
def test_doctest_unex_importerror_with_module(self, testdir):
@@ -227,7 +229,7 @@ class TestDoctests:
# doctest is never executed because of error during hello.py collection
result.stdout.fnmatch_lines([
"*ERROR collecting hello.py*",
"*ImportError: No module named *asdals*",
"*{e}: No module named *asdals*".format(e=MODULE_NOT_FOUND_ERROR),
"*Interrupted: 1 errors during collection*",
])

View File

@@ -249,6 +249,18 @@ class TestPython:
snode = tnode.find_first_by_tag("skipped")
snode.assert_attr(type="pytest.skip", message="hello25", )
def test_mark_skip_doesnt_capture_output(self, testdir):
testdir.makepyfile("""
import pytest
@pytest.mark.skip(reason="foo")
def test_skip():
print("bar!")
""")
result, dom = runandparse(testdir)
assert result.ret == 0
node_xml = dom.find_first_by_tag("testsuite").toxml()
assert "bar!" not in node_xml
def test_classname_instance(self, testdir):
testdir.makepyfile("""
class TestClass:
@@ -703,6 +715,10 @@ def test_logxml_makedir(testdir):
assert result.ret == 0
assert testdir.tmpdir.join("path/to/results.xml").check()
def test_logxml_check_isdir(testdir):
"""Give an error if --junit-xml is a directory (#2089)"""
result = testdir.runpytest("--junit-xml=.")
result.stderr.fnmatch_lines(["*--junitxml must be a filename*"])
def test_escaped_parametrized_names_xml(testdir):
testdir.makepyfile("""

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