Compare commits

...

572 Commits
3.6.4 ... 3.8.2

Author SHA1 Message Date
Anthony Sottile
d3673c7429 Preparing release version 3.8.2 2018-10-02 07:46:02 -07:00
Bruno Oliveira
25fe3706a4 Merge pull request #4056 from nicoddemus/unicode-vars
Ensure Monkeypatch setenv and delenv use bytes keys in Python 2
2018-10-02 07:56:32 -03:00
Bruno Oliveira
1a323fbd3c Show a warning when non-str is given to Monkeypatch.setenv 2018-10-01 20:07:07 -03:00
Bruno Oliveira
9d971d33be Hide internal pytest.warns traceback 2018-10-01 18:45:08 -03:00
Bruno Oliveira
bc009a8582 Fix test to comply with pypy 6.0 2018-10-01 18:37:27 -03:00
Bruno Oliveira
5e7d427df1 Merge pull request #4060 from nicoddemus/4051-changelog
Improve changelog for #4051
2018-10-01 18:12:52 -03:00
Bruno Oliveira
dd59ed3b18 Merge pull request #4059 from labcodes/documenting-scopes
Add possible values for fixture scope to docs
2018-10-01 17:25:42 -03:00
Bruno Oliveira
20d0f0e56b Improve changelog for #4051 2018-10-01 17:12:05 -03:00
Bruno Oliveira
d24a7e6c5a Issue warning if Monkeypatch.setenv/delenv receive non-strings in Python 2
Fixes the bug described in:

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

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

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

Fix #4036
2018-09-25 17:38:22 -03:00
Bruno Oliveira
b1fbb2ab92 Merge pull request #4032 from hjwp/patch-1
add documentation of register_assert_rewrite
2018-09-25 08:43:29 -03:00
Daniel Hahler
e85edf5212 Merge pull request #4029 from nicoddemus/warnings-example-deprecation-docs
Add an example on how to update config.warn calls
2018-09-25 13:25:21 +02:00
Bruno Oliveira
b03bad5dbb Fix linting 2018-09-25 08:12:55 -03:00
Harry Percival
19ec300b2a fix rst syntax again 2018-09-25 06:58:47 +01:00
Harry Percival
11442f2ad7 fix rst syntax thing 2018-09-25 06:57:33 +01:00
Harry Percival
97748b6605 mention conftest.py as a good place to do it. 2018-09-25 06:55:28 +01:00
Harry Percival
2b762337bd add documentation of register_assert_rewrite
wip
2018-09-25 06:49:50 +01:00
Bruno Oliveira
9899b8f1fb Add an example on how to update config.warn calls
As commented in https://github.com/pytest-dev/pytest-cov/pull/230#pullrequestreview-157958838
2018-09-23 22:42:09 -03:00
Anthony Sottile
4474beeb82 Typo fix [ci skip] 2018-09-23 18:07:28 -07:00
Ronny Pfannschmidt
eca3e781b6 Merge pull request #4022 from iwanb/fix_reload
Fix #3539: reload module with assertion rewrite import hook
2018-09-23 18:17:56 +02:00
iwanb
c61ff31ffa Fix #3539: reload module with assertion rewrite import hook 2018-09-23 13:05:55 +02:00
Ankit Goel
ec57cbf82d Merge pull request #4020 from crazymerlyn/release-3.8.1
Preparing release version 3.8.1
2018-09-23 00:56:27 +05:30
CrazyMerlyn
3f6a46c2a4 Preparing release version 3.8.1 2018-09-22 16:34:06 +00:00
Bruno Oliveira
4ba3cb25b0 Merge pull request #4016 from williamjamir/patch-1
Include Python 3.7 on getting started doc
2018-09-21 20:02:25 -03:00
William Jamir Silva
650c458df9 Include Python 3.7 on getting started doc
Close #3932
2018-09-21 19:18:51 -03:00
Ankit Goel
58aa4f91f5 Merge pull request #4012 from maxalbert/fix-docstring-typo
Fix typo in docstring
2018-09-21 22:07:57 +05:30
Maximilian Albert
9b382ed16c Fix typo in docstring 2018-09-21 17:11:15 +01:00
Ronny Pfannschmidt
f02dbaf97f Merge pull request #4010 from nicoddemus/package-len-error-3749
Fix 'Package has no len()' error during collection
2018-09-21 07:40:20 +02:00
Bruno Oliveira
41f6ea13ce Fix 'Package has no len()' error during collection
Fix #3749
2018-09-20 17:53:21 -03:00
Ronny Pfannschmidt
f6eb39df33 Merge pull request #4001 from asottile/fix_bytes_repr_text_mix_python_2
Fix UnicodeDecodeError in assertion with mixed non-ascii bytes repr + text
2018-09-20 22:16:37 +02:00
Bruno Oliveira
7a5e11bbcf Merge pull request #3997 from nicoddemus/deprecation-docs
Introduce deprecations page
2018-09-20 08:22:51 -03:00
Anthony Sottile
7122fa5613 Fix UnicodeDecodeError in assertion with mixed non-ascii bytes repr + text 2018-09-19 20:24:00 -07:00
Bruno Oliveira
7aff81739e Merge pull request #3998 from blueyed/logging-del
logging: del item.catch_log_handler only in teardown
2018-09-19 20:07:19 -03:00
Bruno Oliveira
27772f67c0 Merge pull request #3987 from nicoddemus/fix-find-scope-3941
Fix scope determination with indirect parameters
2018-09-19 20:06:45 -03:00
Bruno Oliveira
10b3b2dc68 Merge pull request #3990 from blueyed/coverage-source
coverage: use modules
2018-09-19 19:55:11 -03:00
Bruno Oliveira
c2841542af Introduce deprecations page
fix #3996
2018-09-19 19:51:29 -03:00
wim glenn
1f28096587 Merge pull request #4003 from pytest-dev/wimglenn-patch-1
seems this subdir is now .pytest_cache not .cache
2018-09-19 14:49:38 -05:00
wim glenn
e86b01e831 Update customize.rst 2018-09-19 14:06:36 -05:00
Bruno Oliveira
d1fa8ae08e Improve CHANGELOG entry 2018-09-19 12:52:10 -03:00
Ronny Pfannschmidt
29dac03314 Merge pull request #3980 from nicoddemus/rewrite-cwd-changed
Fix assertion rewriter crash if cwd changes mid-testing
2018-09-19 17:45:26 +02:00
Daniel Hahler
e7eb7e799b logging: del item.catch_log_handler only in teardown
Without this caplog.record_tuples etc is not available anymore when using
`--pdb`.
2018-09-19 17:17:47 +02:00
Bruno Oliveira
7f48f552c1 Fix linting 2018-09-19 10:18:05 -03:00
Bruno Oliveira
1e2e65f0fa Add references to the relevant Python issues 2018-09-19 08:20:23 -03:00
Daniel Hahler
28c9cc7321 coverage: use modules for source
This should increase coverage for subprocesses, where previously
`source` paths were used only from the config file, but not the initial
`--source` argument.
2018-09-19 07:46:19 +02:00
Bruno Oliveira
ccb90b5c46 [WIP] Introduce deprecations page
fix #3996
2018-09-18 20:56:40 -03:00
Bruno Oliveira
37d2469266 Use a PurePath instance to do matching against patterns in assertion rewrite
This way we don't need to have real file system path, which prevents the
original #3973 bug.
2018-09-17 20:29:09 -03:00
Bruno Oliveira
1df6d28080 Fix assertion rewriter crash if cwd changes mid-testing
Unfortunately we need to get a `py.path.local` object to perform the fnmatch
operation, it is different from the standard `fnmatch` module because it
implements its own custom logic. So we need to use `py.path` to perform
the fnmatch for backward compatibility reasons.

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

Fix #3973
2018-09-17 20:04:44 -03:00
Daniel Hahler
03eaad376b tox: coverage factor: combine and report 2018-09-17 14:44:47 +02:00
Daniel Hahler
739f9a4a4b Travis: use codecov-bash
Faster to install and will retry uploads on connection errors.
2018-09-17 14:44:47 +02:00
Daniel Hahler
93224f8cf9 tox: remove obsolete whitelist_externals 2018-09-17 14:44:47 +02:00
Ronny Pfannschmidt
bb57186dd4 Merge pull request #3983 from nicoddemus/update-backward-policy
Review backward compatibility policy
2018-09-16 20:43:55 +02:00
Bruno Oliveira
2803eb9fbb Merge pull request #3984 from nicoddemus/fix-docs-formatting
Fix rendering of the ini example for python_files
2018-09-15 12:05:59 -03:00
Ronny Pfannschmidt
f53eff93db Merge pull request #3982 from nicoddemus/ignore-pytest-cache
Ignore pytest cache
2018-09-15 07:21:45 +02:00
Bruno Oliveira
86a14d007d Fix scope determination with indirect parameters
Fix #3941
2018-09-14 21:33:59 -03:00
Bruno Oliveira
a4dd6ee3ce Fix linting 2018-09-14 17:31:01 -03:00
Bruno Oliveira
130cf7e0db Fix rendering of the ini example for python_files
Also added an example using one pattern per line
2018-09-14 17:27:25 -03:00
Bruno Oliveira
cbb41f1ae2 Ignore Sphinx's .doctrees folder 2018-09-14 16:00:35 -03:00
Bruno Oliveira
fa78da3c03 Update backward compatibility policy with new practices 2018-09-14 15:58:22 -03:00
Bruno Oliveira
87ddb2dbd5 Change flaky test_request_garbage to provide more debug information
This test fails *very* rarely when running in xdist.
2018-09-14 15:25:45 -03:00
Bruno Oliveira
9aa6b0903b .pytest_cache is now automatically ignored by Git 2018-09-14 15:16:40 -03:00
Bruno Oliveira
49800ea134 Merge pull request #3977 from RonnyPfannschmidt/remove-im-func
Remove im_func
2018-09-13 15:46:33 -03:00
Ronny Pfannschmidt
8fe55b1d18 add changelog for fix #3975 2018-09-13 15:40:45 +02:00
Ronny Pfannschmidt
a0ce9a4441 remove the legacy code about im_func and generalize using fix and compat.getimfunc 2018-09-13 15:38:36 +02:00
Daniel Hahler
2cf2dc3d95 Merge pull request #3967 from blueyed/optional-mock
tests: use unittest.mock with py34+
2018-09-13 07:36:42 +02:00
Daniel Hahler
7537e94ddf tests: use unittest.mock with py34+
Fixes https://github.com/pytest-dev/pytest/issues/3965.

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

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

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

Node.warn(warning_instance)  (recommended)

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

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

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

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

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

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

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

closes #3888

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

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

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

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

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

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

Fix #3747
2018-08-01 16:38:43 -03:00
Kale Kundert
b8255308d6 Make the infinite-recusrion fix more explicit.
So we remember what happened and don't accidentally regress in the
future.
2018-08-01 12:11:03 -07:00
Bruno Oliveira
a5c0fb7f6b Rename recursive_map -> _recursive_list_map as requested in review 2018-08-01 15:17:58 -03:00
Bruno Oliveira
f25683354e Merge pull request #3760 from RonnyPfannschmidt/fix-3757-pin-pathlib
fix #3757 by pinning to pathlib2 that supports __fspath__
2018-08-01 09:44:30 -03:00
Bruno Oliveira
7d13599ba1 Fix recursion in pytest.approx() with arrays in numpy<1.13 2018-08-01 08:04:09 -03:00
Bruno Oliveira
43664d7841 Use ids for parametrized values in test_expected_value_type_error 2018-08-01 07:34:08 -03:00
Bruno Oliveira
2a2f888909 Move recursive_map from local to free function 2018-08-01 07:30:40 -03:00
Bruno Oliveira
ad5ddaf55a Simplify is_numpy_array as suggested in review 2018-08-01 07:28:39 -03:00
Bruno Oliveira
4588130c1e Merge pull request #3756 from RonnyPfannschmidt/fix-3745
fix #3745 - display absolute cache_dir if necessary
2018-08-01 07:09:19 -03:00
Bruno Oliveira
5003bae0de Fix 'at' string for non-numeric messages in approx() 2018-08-01 07:07:37 -03:00
Bruno Oliveira
6e32a1f73d Use parametrize in repr test for nd arrays 2018-08-01 07:04:25 -03:00
Bruno Oliveira
611d254ed5 Improve error checking messages: add position and use pprint 2018-08-01 07:01:00 -03:00
Ronny Pfannschmidt
57a8f208bc fix #3757 by pinning to pathlib2 that supports __fspath__ 2018-08-01 11:45:39 +02:00
Ronny Pfannschmidt
fcdc1d867e fix #3745 - display absolute cache_dir if necessary 2018-08-01 08:25:37 +02:00
Bruno Oliveira
098dca3a9f Use {!r} for a few other messages as well 2018-07-31 21:14:51 -03:00
Bruno Oliveira
8e2ed76227 Create appropriate CHANGELOG entries 2018-07-31 21:11:26 -03:00
Bruno Oliveira
bf7c188cc0 Improve error message for invalid types passed to pytest.approx()
* Hide the internal traceback
* Use !r representation instead of !s (the default for {} formatting)
2018-07-31 21:08:24 -03:00
Bruno Oliveira
8c9efd8608 Only call _collectfile on package instances
As discussed in #3751, this feels like a hack, pushing it only so we can
see how it fares on CI and if there are better solutions out there
2018-07-31 19:06:30 -03:00
Bruno Oliveira
e1ad1a14af Add example script and failure for #3742 2018-07-31 17:50:55 -03:00
Kale Kundert
327fe4cfcc Update the changelog. 2018-07-31 11:40:02 -07:00
Kale Kundert
d02491931a Fix the unused import. 2018-07-31 11:33:46 -07:00
Kale Kundert
032db159c9 Let black reformat the code... 2018-07-31 11:23:23 -07:00
Kale Kundert
cd2085ee71 approx(): Detect type errors earlier. 2018-07-31 00:26:35 -07:00
Kale Kundert
ad305e71d7 Improve docstrings for Approx classes. 2018-07-30 23:26:57 -07:00
Kale Kundert
7d8688d54b Reflect dimension in approx repr for numpy arrays. 2018-07-30 23:23:17 -07:00
Bruno Oliveira
253419316c Merge pull request #3738 from nicoddemus/release-3.7.0
Release 3.7.0
2018-07-30 20:38:22 -03:00
Bruno Oliveira
997ef59306 Fix typos in CHANGELOG 2018-07-30 18:31:35 -03:00
Bruno Oliveira
60b1913ba2 Preparing release version 3.7.0 2018-07-30 20:14:42 +00:00
Bruno Oliveira
2c09930b6d Use proper quotes for python 3.7 on travis.yml 2018-07-30 20:13:17 +00:00
Bruno Oliveira
d461e931dd Use python 3.6 for regendoc 2018-07-30 20:12:52 +00:00
Bruno Oliveira
eada0b1fd7 Merge remote-tracking branch 'upstream/master' into release-3.7.0 2018-07-30 20:12:30 +00:00
Bruno Oliveira
150535b6c1 Merge pull request #3696 from abrammer/approx_numpy_tolerance_bugfix
bugfix in ApproxNumpy initialisation, use keywords for arguments to fix
2018-07-30 17:09:18 -03:00
Ronny Pfannschmidt
f1ec02cdcd Merge pull request #3733 from nicoddemus/py37
Test with Python 3.7 on Travis and AppVeyor
2018-07-30 20:02:03 +02:00
Ronny Pfannschmidt
9f5d73d44a Merge pull request #3735 from nicoddemus/deprecate-pytest-namespace
Deprecate pytest namespace
2018-07-30 19:55:45 +02:00
Bruno Oliveira
8609f8d25a Move warning definition to deprecated module 2018-07-30 14:25:29 -03:00
Bruno Oliveira
953a618102 Update CHANGELOG entry about pytest_namespace deprecation 2018-07-30 12:18:37 -03:00
Bruno Oliveira
cf6d8e7e53 Fix test and update warning in pytest_namespace docs 2018-07-30 12:16:42 -03:00
Bruno Oliveira
8af78f417f Merge pull request #3732 from nicoddemus/merge-master-into-features
Merge master into features
2018-07-30 07:26:19 -03:00
abrammer
535fd1f311 may as well include inf test while we're at it 2018-07-29 23:12:04 -04:00
abrammer
762eaf443a update changelog to include the addition of tests 2018-07-29 22:57:39 -04:00
abrammer
330640eb96 update tests to check tolerance args and expecing nan in numpy arrays 2018-07-29 22:47:38 -04:00
Bruno Oliveira
e3d412d1f4 Warn when implementations exist for pytest_namespace hook
This hook has been deprecated and will be removed in the future.

Fix #2639
2018-07-29 22:20:23 -03:00
Bruno Oliveira
6f9a12a8a3 Merge pull request #3486 from ammarnajjar/last-failed-no-failures_docs_correction
--last-failed-no-failures docs correction
2018-07-29 21:26:03 -03:00
Bruno Oliveira
0e47599572 Merge remote-tracking branch 'upstream/master' into merge-master-into-features 2018-07-29 21:15:51 -03:00
Bruno Oliveira
c480223e88 Test with Python 3.7 on Travis and AppVeyor 2018-07-29 21:14:38 -03:00
Bruno Oliveira
0b522d40a7 Merge pull request #3734 from nicoddemus/fix-docs
Fix reference to _Result in docs
2018-07-29 21:14:09 -03:00
Bruno Oliveira
d900a6c8bd Merge pull request #3731 from asottile/pygrep_hooks
Use upstream rst-backticks hook
2018-07-29 20:52:28 -03:00
Bruno Oliveira
fe46fbb719 Fix reference to _Result in docs 2018-07-29 20:50:24 -03:00
Anthony Sottile
8d401cdb9d Use upstream rst-backticks hook 2018-07-29 15:46:06 -07:00
Bruno Oliveira
3f3f6f1be4 Merge pull request #3729 from nicoddemus/fix-changelog-titles
Fix "Pytest" to "pytest" in the CHANGELOG
2018-07-29 19:42:24 -03:00
Bruno Oliveira
b6da5cc54c Fix "Pytest" to "pytest" in the CHANGELOG
Now that we have fixed towncrier to render the proper title, seems fitting
to update the others
2018-07-28 12:57:18 -03:00
Bruno Oliveira
eaeeedc9c3 Merge pull request #3728 from nicoddemus/release-3.6.4
Release 3.6.4
2018-07-28 12:53:49 -03:00
Kale Kundert
bf127a63b2 Need to iterate over the flattened array. 2018-07-27 11:24:42 -07:00
Bruno Oliveira
fe16f81da1 Merge pull request #3705 from nicoddemus/deprecate-call-fixture-func
Deprecate calling fixture functions directly
2018-07-27 15:09:09 -03:00
Bruno Oliveira
d0ba242c46 Implement change suggested by @kalekundert in PR 2018-07-27 15:07:20 -03:00
Bruno Oliveira
57b0c60cb4 Remove Testdir.run_example as recommended 2018-07-26 20:10:40 -03:00
Bruno Oliveira
6e57d123bb Mark test_idval_hypothesis as flaky on Windows (#3707) 2018-07-26 19:58:42 -03:00
Bruno Oliveira
011f88f7e7 Deprecate calling fixture functions directly
This will now issue a RemovedInPytest4Warning when the user calls
a fixture function directly, instead of requesting it from test
functions as is expected

Fix #3661
2018-07-26 19:58:42 -03:00
Bruno Oliveira
2eb9301ad5 Improve CHANGELOG 2018-07-25 08:09:31 -03:00
abrammer
f0db64ac2e drop the duplicate approx call
update test to include both np.array(actual) and np.array(expected)
2018-07-24 21:18:44 -04:00
abrammer
514ca6f4ad add test wrt #3695 checking numpy array tolerance args 2018-07-23 23:40:06 -04:00
Ronny Pfannschmidt
f8749eeb5c Merge pull request #3708 from nicoddemus/small-refactors
Small refactorings
2018-07-23 06:53:08 +02:00
Bruno Oliveira
f5165064ee Make yield_fixture just call fixture to do its work
Since fixture and yield_fixture are identical, they should call
the same code; as it was, the code inside them was already starting
to deviate.
2018-07-22 09:41:03 -03:00
Bruno Oliveira
c9a0881309 Isolate the code that resolves the fixturefunc to a separate function
pytest_fixture_setup was somewhat convoluted because it was trying
to do too many things.
2018-07-22 09:37:41 -03:00
Bruno Oliveira
5167933395 Move teardown code of yield fixtures to a partial to avoid leaks
As it were before, it was keeping a reference to fixturefunc and it
alive when an error occurred
2018-07-22 09:27:34 -03:00
Alan Brammer
75db608479 update changelog 2018-07-18 17:56:00 -04:00
Alan
7bff5866b1 bugfix in ApproxNumpy initialisation, use keywords for arguments now 2018-07-18 17:29:55 -04:00
Bruno Oliveira
0bb29d5649 Merge pull request #3685 from nicoddemus/merge-master-into-features
Merge master into features
2018-07-15 16:53:39 -03:00
Bruno Oliveira
db33f03c15 Merge pull request #3681 from tadeoos/980-fix-truncated-locals-in-verbose
Fix truncated locals in verbose mode
2018-07-15 14:43:15 -03:00
Bruno Oliveira
ac9ceaacd8 Merge remote-tracking branch 'upstream/master' into merge-master-into-features 2018-07-15 11:54:14 -03:00
Tadek Teleżyński
d2fe619120 Fix truncated locals in verbose mode 2018-07-15 11:30:26 -03:00
Bruno Oliveira
f6ceedd15b Merge pull request #3636 from RonnyPfannschmidt/fixturetest-examples
[RFC] Fixturetest examples - move test contents to use example scripts for contents
2018-07-11 23:29:33 -03:00
Bruno Oliveira
5226c7fac3 Merge pull request #3665 from nicoddemus/changelog-tweaks
Small tweaks to the changelog entries
2018-07-10 21:12:50 -03:00
Bruno Oliveira
803302e70c Fix end-of-line in 2220.bugfix.rst 2018-07-07 11:13:48 -03:00
Bruno Oliveira
05f1d0d3ef Update README for CHANGELOG about using multiple paragraphs 2018-07-07 11:07:13 -03:00
Bruno Oliveira
1cd62f8c38 Update CHANGELOG template to put issue links at the start of entries
This allows us to use the new multi-line entries available with
towncrier 18.6.0
2018-07-07 11:02:33 -03:00
Bruno Oliveira
a522fc745a Small tweaks to the changelog entries 2018-07-07 10:43:37 -03:00
Bruno Oliveira
303133f013 Merge pull request #3647 from jeffreyrack/3610-add-trace-option
3610 add trace option
2018-07-07 10:05:34 -03:00
Ronny Pfannschmidt
1e94ac784f Merge pull request #3389 from jonozzz/features
Add package scoped fixtures #2283
2018-07-06 11:42:36 +02:00
Bruno Oliveira
027d2336b8 Add minimal docs for package-scoped fixtures (experimental) 2018-07-05 21:56:31 -03:00
Bruno Oliveira
3c19370cec Merge remote-tracking branch 'upstream/features' into jonozzz/features 2018-07-05 18:15:17 -03:00
Bruno Oliveira
3f5e06ecc4 Merge pull request #3659 from nicoddemus/merge-master-into-features
Merge master into features
2018-07-04 21:11:28 -03:00
Bruno Oliveira
7696d5371a Merge remote-tracking branch 'upstream/master' into features 2018-07-04 18:49:35 -03:00
Jeffrey Rackauckas
067de257e1 Fix test_pdb.py with pexpect 2018-07-02 21:03:21 -07:00
Jeffrey Rackauckas
4a925ef5e9 Fixing bug in test. 2018-07-02 20:29:59 -07:00
Jeffrey Rackauckas
4afb8c428b Fix python 2 issues 2018-07-02 20:20:42 -07:00
Jeffrey Rackauckas
2f1a2cf07f Fixing --trace test. 2018-07-02 19:55:08 -07:00
Jeffrey Rackauckas
6cc4fe2412 Fixing bad indentation 2018-07-02 19:53:46 -07:00
Jeffrey Rackauckas
10a8691eca Add support for yielded functions. 2018-07-02 19:46:26 -07:00
Jeffrey Rackauckas
b75320ba95 Fix --trace option with yield tests. 2018-07-02 19:08:41 -07:00
Jeffrey Rackauckas
bc268a58d1 Adding needed newline 2018-07-01 20:22:50 -07:00
Jeffrey Rackauckas
0b70477930 Fix linting issues. 2018-07-01 20:18:00 -07:00
Jeffrey Rackauckas
8801162275 Fixing tabbing in usage.rst. 2018-07-01 18:54:04 -07:00
Jeffrey Rackauckas
a604a71185 Fixing usage.rst title. 2018-07-01 18:53:18 -07:00
Jeffrey Rackauckas
66fa6bb42e Fix flake8 issues. 2018-07-01 18:50:57 -07:00
Jeffrey Rackauckas
713d32c4da Adding documentation for the --trace option. 2018-07-01 18:49:39 -07:00
Jeffrey Rackauckas
57198d477b Adding changelog entry for the --trace option. 2018-07-01 12:14:35 -07:00
Jeffrey Rackauckas
533f4cc10c Fix test to pass 2018-06-30 21:36:27 -07:00
Jeffrey Rackauckas
a46b94950c Properly set immediately_break value 2018-06-30 21:32:25 -07:00
Jeffrey Rackauckas
952bbefaac Add initial test. 2018-06-30 18:26:58 -07:00
Jeffrey Rackauckas
54d3cd587d Adding the --trace option. 2018-06-30 18:09:06 -07:00
Ronny Pfannschmidt
0fd86ec8a8 move some fill fixture acceptance tests contents to the examples script folder 2018-06-29 10:58:33 +02:00
Ronny Pfannschmidt
4ae7e9788c fix quotes in scope order test 2018-06-29 07:13:18 +02:00
Ronny Pfannschmidt
5582ad0445 remove use of formatting in test_func_closure_module_auto
this makes it apparent that pytester should supply some kind of variable support
2018-06-29 07:07:03 +02:00
Ronny Pfannschmidt
982b614010 remove format calls for most fixture tests 2018-06-29 07:07:03 +02:00
Ronny Pfannschmidt
7845ab4bc3 remove test file formatting from TestContextManagerFixtureFuncs 2018-06-29 07:07:03 +02:00
Bruno Oliveira
8680dfc939 Merge pull request #3629 from egnartsms/issue-2220-param-breaks-dep
Make test parametrization override indirect fixtures
2018-06-28 21:43:21 -03:00
Serhii Mozghovyi
76ac670f7d Add changelog description 2018-06-28 23:42:18 +03:00
Bruno Oliveira
7b47dfb744 Merge pull request #3634 from RonnyPfannschmidt/merge-from-master
Merge from master
2018-06-28 14:05:18 -03:00
Ronny Pfannschmidt
3c73d6298a merge from master to features 2018-06-28 17:32:41 +02:00
Serhii Mozghovyi
c220fb235a Minor fix (code improvement) 2018-06-28 14:53:06 +03:00
Serhii Mozghovyi
1dc5e97ac2 Make test parametrization override indirect fixtures 2018-06-28 14:32:29 +03:00
Bruno Oliveira
e9371a58a0 Merge pull request #3622 from RonnyPfannschmidt/builtin-serialize
move report classes to own file to prepare for serialisazion
2018-06-27 15:17:09 -03:00
Bruno Oliveira
ea379ba10f Merge pull request #3623 from RonnyPfannschmidt/pytester-runexamples
Pytester runexamples
2018-06-27 09:13:29 -03:00
Ronny Pfannschmidt
17e01993d9 regendoc and invocation fixes 2018-06-27 08:28:21 +02:00
Ronny Pfannschmidt
8a6345515b regendoc 2018-06-27 06:52:54 +02:00
Ronny Pfannschmidt
581d49635e add docs and changelog 2018-06-27 06:52:36 +02:00
Ronny Pfannschmidt
e860ff7299 port some acceptance tests over to copy_example 2018-06-26 22:59:40 +02:00
Ronny Pfannschmidt
0672bc633f enable pytester to run examples copied from the cwd 2018-06-26 22:48:33 +02:00
Ronny Pfannschmidt
2dfb52f7e0 fix rebase artifacts 2018-06-26 22:10:26 +02:00
Ronny Pfannschmidt
cc6eb9f83c move test reports to own file 2018-06-26 22:09:15 +02:00
Ronny Pfannschmidt
6b239263da Merge pull request #3620 from RonnyPfannschmidt/merge-from-master
Merge from master
2018-06-26 21:56:09 +02:00
Ronny Pfannschmidt
89e0a3ec27 merge from master to features 2018-06-26 17:01:05 +02:00
Bruno Oliveira
5b186cd609 Merge pull request #3594 from pytest-dev/interal-pathlib
[WIP] port cache plugin internals to pathlib
2018-06-25 11:09:36 -03:00
Ronny Pfannschmidt
5a156b3645 disable pypy on windows until scandir works for it 2018-06-24 22:54:26 +02:00
Ronny Pfannschmidt
95f00de0df use paths for config.cache.get key 2018-06-23 00:14:06 +02:00
Ronny Pfannschmidt
c4c666cbc4 use Pathlib instead of path splitting 2018-06-23 00:07:57 +02:00
Ronny Pfannschmidt
ee30bf45c9 rebase onto readme addition 2018-06-23 00:03:10 +02:00
Ronny Pfannschmidt
603df1ea1c whops, its supported starting with python 3.6, not python 3.5 2018-06-22 23:56:22 +02:00
Ronny Pfannschmidt
abbf73ad1a use pathlib2 up to python3.4 - damn the stdlib 2018-06-22 23:56:22 +02:00
Ronny Pfannschmidt
1226cdab47 fix warnings and json dumping of cacheprovider 2018-06-22 23:56:22 +02:00
Ronny Pfannschmidt
ab80e0fba0 sort compat flake8 mess correctly 2018-06-22 23:56:22 +02:00
Ronny Pfannschmidt
fb992a0c81 reorder attr.ib specs 2018-06-22 23:56:22 +02:00
Ronny Pfannschmidt
23581d44bd add missed file 2018-06-22 23:56:22 +02:00
Ronny Pfannschmidt
c7eb53317b port cache plugin internals to pathlib
warning logging got broken by detanglement from config
2018-06-22 23:56:22 +02:00
Bruno Oliveira
de98939ebf Merge pull request #3608 from avirlrma/features
add reamde for .pytest_cache
2018-06-21 21:05:23 -03:00
Bruno Oliveira
0d3914b626 Remove extra '\' left at the end of a line in cache's readme contents 2018-06-21 20:12:50 -03:00
Bruno Oliveira
eb94bce3e2 Change 3519 to trivial 2018-06-21 20:11:22 -03:00
Bruno Oliveira
b897008887 Improve CHANGELOG grammar 2018-06-21 20:09:32 -03:00
avirlrma
998d540b73 fixed changelog entry 2018-06-21 17:56:26 +05:30
avirlrma
c672bfa32e added changelog entry
moved cache readme tests to test_cacheprovider.py
2018-06-21 17:43:10 +05:30
avirlrma
8f1d8ac970 fixed linting errors
ran black
removed unused imports and variables
2018-06-21 15:15:55 +05:30
avirlrma
53d4710c62 added tests for .pytest_cache README
Helper class to check if readme exists in .pytest_cache directory
 Tests to check for readme when tests pass and when they fail
2018-06-21 14:25:00 +05:30
avirlrma
31f089db6a add reamde for .pytest_cache
method - `ensure_readme()`
2018-06-21 13:14:58 +05:30
Bruno Oliveira
9d60cf25c0 Merge pull request #2207 from RonnyPfannschmidt/fix/519
add example scripts for issue #519
2018-06-15 15:05:18 -03:00
Bruno Oliveira
9e32b6ae48 Small typo and grammar fix 2018-06-15 15:05:00 -03:00
Ronny Pfannschmidt
99402cf1c0 add a readme to the example scripts 2018-06-15 20:02:01 +02:00
Ronny Pfannschmidt
3ac2ae3c8c black 2018-06-15 18:13:45 +02:00
Ronny Pfannschmidt
ea906056fa add the actually expected fixtureorder for #519 2018-06-15 18:04:24 +02:00
Ronny Pfannschmidt
c081c5ee23 add example scripts for issue #519 2018-06-15 18:04:24 +02:00
Bruno Oliveira
3dcdaab103 Merge pull request #3585 from wcooley/feature/3579-caplog-messages
Add `messages` property to `caplog` fixture.
2018-06-15 12:41:33 -03:00
Wil Cooley
3615977608 Add messages property to caplog fixture. 2018-06-14 12:22:33 -07:00
Bruno Oliveira
94c41bec64 Merge pull request #3576 from RonnyPfannschmidt/addmarker-api
fix addmarker - extract mark from markdecorator
2018-06-13 18:36:40 -03:00
Ronny Pfannschmidt
8d072205e9 fix whitespace 2018-06-13 22:00:22 +02:00
Bruno Oliveira
b5102d03a6 Fix add_marker docs 2018-06-13 14:57:10 -03:00
Ronny Pfannschmidt
791bb3502c changelog 2018-06-13 17:29:42 +02:00
Ronny Pfannschmidt
eb0c6a8287 fix addmarker - extract mark from markdecorator 2018-06-13 17:27:00 +02:00
Ammar Najjar
9ddd573774 Issue #3295: add changelog doc entry for adding a missing argument in
the examples
2018-05-17 23:11:37 +02:00
Ammar Najjar
f99da9058f Issue #3295: Correct the usage of --last-failed-no-failures documentation
- add the missing --last-failed argument in the presented examples, for they are missleading and lead to think that the missing argument is not needed.
2018-05-17 23:07:55 +02:00
turturica
7d0dba18de Removed _CompatProperty("Package") 2018-04-27 10:23:15 -07:00
turturica
6fc7f07a80 Workaround for py36-xdist failure. 2018-04-26 23:05:03 -07:00
turturica
05b5b64379 Merge remote-tracking branch 'upstream/features' into features 2018-04-25 21:20:39 -07:00
turturica
229c8e551d Fix parametrized fixtures reordering. 2018-04-25 18:44:54 -07:00
turturica
d483b401ee Merge remote-tracking branch 'upstream/features' into features 2018-04-24 13:45:10 -07:00
turturica
acacf75f49 Added another package-scoped fixture test.
Changed existing complex tests to use package fixtures.
2018-04-24 13:32:58 -07:00
turturica
f8350c6304 Fix an issue that popped up only on Windows. 2018-04-21 19:51:33 -07:00
turturica
fedc78522b Build a stack of all previous packages instead of just the one closest to the initial argument(s).
Address #3358 by caching nodes in a session dict.
2018-04-21 18:39:42 -07:00
turturica
b0474398ec Fix a formatting error. 2018-04-20 18:18:44 -07:00
turturica
dc90c9108f Collapse all parent nested package fixtures when pointing to a sub-node.
Example:
Given this hierarchy: p1.s1.s2.s3
I want to run pytest p1/s1/s2/s3/foo.py

If there are any package fixtures defined at p1..s2 levels, they should also be executed.
2018-04-20 17:15:09 -07:00
turturica
69031d0033 Forgot one file from previous commit. 2018-04-20 15:54:21 -07:00
turturica
e44d4e6508 Merge remote-tracking branch 'upstream/features' into features 2018-04-20 15:21:24 -07:00
turturica
c416b1d935 Don't stop at the first package when looking up package-scoped fixtures.
Example:
package1.subpackage1
package1.subpackage2

package1's setup/teardown were executed again when exiting subpackage1 and entering subpackage2.
2018-04-20 15:04:58 -07:00
turturica
7d923c389e Merge remote-tracking branch 'upstream/features' into features 2018-04-18 00:11:03 -07:00
turturica
c02e8d8b0d Fix test collection when tests are passed as IDs at the command line. Note this is still broken due to #3358. 2018-04-16 11:44:05 -07:00
turturica
35df2cdbee Fix linting error. 2018-04-11 15:45:43 -07:00
turturica
2b1410895e Add package scoped fixtures #2283 2018-04-11 15:39:42 -07:00
173 changed files with 6545 additions and 2294 deletions

View File

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

2
.gitattributes vendored
View File

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

6
.gitignore vendored
View File

@@ -24,6 +24,7 @@ src/_pytest/_version.py
.eggs/
doc/*/_build
doc/*/.doctrees
build/
dist/
*.egg-info
@@ -35,6 +36,11 @@ env/
.cache
.pytest_cache
.coverage
.coverage.*
coverage.xml
.ropeproject
.idea
.hypothesis
.pydevproject
.project
.settings

View File

@@ -5,13 +5,13 @@ repos:
hooks:
- id: black
args: [--safe, --quiet]
language_version: python3.6
language_version: python3
- repo: https://github.com/asottile/blacken-docs
rev: v0.2.0
hooks:
- id: blacken-docs
additional_dependencies: [black==18.6b4]
language_version: python3.6
language_version: python3
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v1.3.0
hooks:
@@ -25,6 +25,10 @@ repos:
rev: v1.2.0
hooks:
- id: pyupgrade
- repo: https://github.com/pre-commit/pygrep-hooks
rev: v1.0.0
hooks:
- id: rst-backticks
- repo: local
hooks:
- id: rst
@@ -33,9 +37,9 @@ repos:
files: ^(CHANGELOG.rst|HOWTORELEASE.rst|README.rst|changelog/.*)$
language: python
additional_dependencies: [pygments, restructuredtext_lint]
python_version: python3.6
- id: rst-backticks
name: rst ``code`` is two backticks
entry: ' `[^`]+[^_]`([^_]|$)'
language: pygrep
types: [rst]
- id: changelogs-rst
name: changelog filenames
language: fail
entry: 'changelog files must be named ####.(feature|bugfix|doc|removal|vendor|trivial).rst'
exclude: changelog/(\d+\.(feature|bugfix|doc|removal|vendor|trivial).rst|README.rst|_template.rst)
files: ^changelog/

View File

@@ -1,8 +1,9 @@
sudo: false
language: python
stages:
- linting
- test
- baseline
- name: test
if: repo = pytest-dev/pytest AND tag IS NOT present
- name: deploy
if: repo = pytest-dev/pytest AND tag IS present
python:
@@ -11,41 +12,60 @@ install:
- pip install --upgrade --pre tox
env:
matrix:
# coveralls is not listed in tox's envlist, but should run in travis
- TOXENV=coveralls
# note: please use "tox --listenvs" to populate the build matrix below
# please remove the linting env in all cases
- TOXENV=py27
- TOXENV=py34
- TOXENV=py36
- TOXENV=py27-pexpect
- TOXENV=py27-xdist
- TOXENV=py27-trial
- TOXENV=py27-numpy
- TOXENV=py27-pluggymaster
- TOXENV=py27-pluggymaster PYTEST_NO_COVERAGE=1
- TOXENV=py36-pexpect
- TOXENV=py36-xdist
- TOXENV=py36-trial
- TOXENV=py36-numpy
- TOXENV=py36-pluggymaster
- TOXENV=py36-pluggymaster PYTEST_NO_COVERAGE=1
- TOXENV=py27-nobyte
- TOXENV=doctesting
- TOXENV=docs
- TOXENV=docs PYTEST_NO_COVERAGE=1
jobs:
include:
- env: TOXENV=pypy
# Coverage tracking is slow with pypy, skip it.
- env: TOXENV=pypy PYTEST_NO_COVERAGE=1
python: 'pypy-5.4'
- env: TOXENV=py35
python: '3.5'
- env: TOXENV=py36-freeze
- env: TOXENV=py36-freeze PYTEST_NO_COVERAGE=1
python: '3.6'
- env: TOXENV=py37
python: 'nightly'
python: '3.7'
sudo: required
dist: xenial
- &test-macos
language: generic
os: osx
osx_image: xcode9.4
sudo: required
install:
- python -m pip install --pre tox
env: TOXENV=py27
- <<: *test-macos
env: TOXENV=py37
before_install:
- brew update
- brew upgrade python
- brew unlink python
- brew link python
- stage: baseline
env: TOXENV=py27
- env: TOXENV=py34
- env: TOXENV=py36
- env: TOXENV=linting PYTEST_NO_COVERAGE=1
- stage: deploy
python: '3.6'
env:
env: PYTEST_NO_COVERAGE=1
install: pip install -U setuptools setuptools_scm
script: skip
deploy:
@@ -58,17 +78,35 @@ jobs:
on:
tags: true
repo: pytest-dev/pytest
- stage: linting
python: '3.6'
env:
install:
- pip install pre-commit
- pre-commit install-hooks
script:
- pre-commit run --all-files
before_script:
- |
if [[ "$PYTEST_NO_COVERAGE" != 1 ]]; then
export COVERAGE_FILE="$PWD/.coverage"
export COVERAGE_PROCESS_START="$PWD/.coveragerc"
export _PYTEST_TOX_COVERAGE_RUN="coverage run -m"
export _PYTEST_TOX_EXTRA_DEP=coverage-enable-subprocess
fi
script: tox --recreate
after_success:
- |
if [[ "$PYTEST_NO_COVERAGE" != 1 ]]; then
set -e
pip install coverage
coverage combine
coverage xml --ignore-errors
coverage report -m --ignore-errors
bash <(curl -s https://codecov.io/bash) -Z -X gcov -X coveragepy -X search -X xcode -X gcovout -X fix -f coverage.xml -F "${TOXENV//-/,},linux"
# Coveralls does not support merged reports.
if [[ "$TOXENV" = py37 ]]; then
pip install coveralls
coveralls
fi
fi
notifications:
irc:
channels:

18
AUTHORS
View File

@@ -10,6 +10,7 @@ Ahn Ki-Wook
Alan Velasco
Alexander Johnson
Alexei Kozlenok
Allan Feldman
Anatoly Bubenkoff
Anders Hovmöller
Andras Tim
@@ -46,7 +47,9 @@ Christian Boelsen
Christian Theunert
Christian Tismer
Christopher Gilling
CrazyMerlyn
Cyrus Maden
Dhiren Serai
Daniel Grana
Daniel Hahler
Daniel Nuri
@@ -71,6 +74,7 @@ Endre Galaczi
Eric Hunsberger
Eric Siegerman
Erik M. Bray
Fabio Zadrozny
Feng Ma
Florian Bruhin
Floris Bruynooghe
@@ -89,6 +93,8 @@ Hugo van Kemenade
Hui Wang (coldnight)
Ian Bicking
Ian Lesperance
Ionuț Turturică
Iwan Briquemont
Jaap Broekhuizen
Jan Balster
Janne Vanhala
@@ -97,6 +103,7 @@ Javier Domingo Cansino
Javier Romero
Jeff Rackauckas
Jeff Widman
Jenni Rinker
John Eddie Ayson
John Towler
Jon Sonesen
@@ -173,6 +180,7 @@ Raphael Pierzina
Raquel Alegre
Ravi Chandra
Roberto Polli
Roland Puntaier
Romain Dorgueil
Roman Bolshakov
Ronny Pfannschmidt
@@ -181,7 +189,9 @@ Russel Winder
Ryan Wooden
Samuel Dion-Girardeau
Samuele Pedroni
Sankt Petersbug
Segev Finer
Serhii Mozghovyi
Simon Gomizelj
Skylar Downes
Srinivas Reddy Thatiparthy
@@ -190,6 +200,7 @@ Stefan Zimmermann
Stefano Taschini
Steffen Allner
Stephan Obermann
Tadek Teleżyński
Tarcisio Fischer
Tareq Alayan
Ted Xiao
@@ -202,14 +213,17 @@ Trevor Bekolay
Tyler Goodlet
Tzu-ping Chung
Vasily Kuznetsov
Victor Maryama
Victor Uriarte
Vidar T. Fauske
Virgil Dupras
Vitaly Lashmanov
Vlad Dragos
Wil Cooley
William Lee
Wim Glenn
Wouter van Ackooy
Xuan Luong
Xuecong Liao
Zac Hatfield-Dodds
Zoltán Máté
Roland Puntaier
Allan Feldman

View File

@@ -1,3 +1,13 @@
=================
Changelog history
=================
Versions follow `Semantic Versioning <https://semver.org/>`_ (``<major>.<minor>.<patch>``).
Backward incompatible (breaking) changes will only be introduced in major versions
with advance notice in the **Deprecations** section of releases.
..
You should *NOT* be adding new change log entries to this file, this
file is managed by towncrier. You *may* edit previous change logs to
@@ -8,6 +18,381 @@
.. towncrier release notes start
pytest 3.8.2 (2018-10-02)
=========================
Deprecations and Removals
-------------------------
- `#4036 <https://github.com/pytest-dev/pytest/issues/4036>`_: The ``item`` parameter of ``pytest_warning_captured`` hook is now documented as deprecated. We realized only after
the ``3.8`` release that this parameter is incompatible with ``pytest-xdist``.
Our policy is to not deprecate features during bugfix releases, but in this case we believe it makes sense as we are
only documenting it as deprecated, without issuing warnings which might potentially break test suites. This will get
the word out that hook implementers should not use this parameter at all.
In a future release ``item`` will always be ``None`` and will emit a proper warning when a hook implementation
makes use of it.
Bug Fixes
---------
- `#3539 <https://github.com/pytest-dev/pytest/issues/3539>`_: Fix reload on assertion rewritten modules.
- `#4034 <https://github.com/pytest-dev/pytest/issues/4034>`_: The ``.user_properties`` attribute of ``TestReport`` objects is a list
of (name, value) tuples, but could sometimes be instantiated as a tuple
of tuples. It is now always a list.
- `#4039 <https://github.com/pytest-dev/pytest/issues/4039>`_: No longer issue warnings about using ``pytest_plugins`` in non-top-level directories when using ``--pyargs``: the
current ``--pyargs`` mechanism is not reliable and might give false negatives.
- `#4040 <https://github.com/pytest-dev/pytest/issues/4040>`_: Exclude empty reports for passed tests when ``-rP`` option is used.
- `#4051 <https://github.com/pytest-dev/pytest/issues/4051>`_: Improve error message when an invalid Python expression is passed to the ``-m`` option.
- `#4056 <https://github.com/pytest-dev/pytest/issues/4056>`_: ``MonkeyPatch.setenv`` and ``MonkeyPatch.delenv`` issue a warning if the environment variable name is not ``str`` on Python 2.
In Python 2, adding ``unicode`` keys to ``os.environ`` causes problems with ``subprocess`` (and possible other modules),
making this a subtle bug specially susceptible when used with ``from __future__ import unicode_literals``.
Improved Documentation
----------------------
- `#3928 <https://github.com/pytest-dev/pytest/issues/3928>`_: Add possible values for fixture scope to docs.
pytest 3.8.1 (2018-09-22)
=========================
Bug Fixes
---------
- `#3286 <https://github.com/pytest-dev/pytest/issues/3286>`_: ``.pytest_cache`` directory is now automatically ignored by Git. Users who would like to contribute a solution for other SCMs please consult/comment on this issue.
- `#3749 <https://github.com/pytest-dev/pytest/issues/3749>`_: Fix the following error during collection of tests inside packages::
TypeError: object of type 'Package' has no len()
- `#3941 <https://github.com/pytest-dev/pytest/issues/3941>`_: Fix bug where indirect parametrization would consider the scope of all fixtures used by the test function to determine the parametrization scope, and not only the scope of the fixtures being parametrized.
- `#3973 <https://github.com/pytest-dev/pytest/issues/3973>`_: Fix crash of the assertion rewriter if a test changed the current working directory without restoring it afterwards.
- `#3998 <https://github.com/pytest-dev/pytest/issues/3998>`_: Fix issue that prevented some caplog properties (for example ``record_tuples``) from being available when entering the debugger with ``--pdb``.
- `#3999 <https://github.com/pytest-dev/pytest/issues/3999>`_: Fix ``UnicodeDecodeError`` in python2.x when a class returns a non-ascii binary ``__repr__`` in an assertion which also contains non-ascii text.
Improved Documentation
----------------------
- `#3996 <https://github.com/pytest-dev/pytest/issues/3996>`_: New `Deprecations and Removals <https://docs.pytest.org/en/latest/deprecations.html>`_ page shows all currently
deprecated features, the rationale to do so, and alternatives to update your code. It also list features removed
from pytest in past major releases to help those with ancient pytest versions to upgrade.
Trivial/Internal Changes
------------------------
- `#3955 <https://github.com/pytest-dev/pytest/issues/3955>`_: Improve pre-commit detection for changelog filenames
- `#3975 <https://github.com/pytest-dev/pytest/issues/3975>`_: Remove legacy code around im_func as that was python2 only
pytest 3.8.0 (2018-09-05)
=========================
Deprecations and Removals
-------------------------
- `#2452 <https://github.com/pytest-dev/pytest/issues/2452>`_: ``Config.warn`` and ``Node.warn`` have been
deprecated, see `<https://docs.pytest.org/en/latest/deprecations.html#config-warn-and-node-warn>`_ for rationale and
examples.
- `#3936 <https://github.com/pytest-dev/pytest/issues/3936>`_: ``@pytest.mark.filterwarnings`` second parameter is no longer regex-escaped,
making it possible to actually use regular expressions to check the warning message.
**Note**: regex-escaping the match string was an implementation oversight that might break test suites which depend
on the old behavior.
Features
--------
- `#2452 <https://github.com/pytest-dev/pytest/issues/2452>`_: Internal pytest warnings are now issued using the standard ``warnings`` module, making it possible to use
the standard warnings filters to manage those warnings. This introduces ``PytestWarning``,
``PytestDeprecationWarning`` and ``RemovedInPytest4Warning`` warning types as part of the public API.
Consult `the documentation <https://docs.pytest.org/en/latest/warnings.html#internal-pytest-warnings>`_ for more info.
- `#2908 <https://github.com/pytest-dev/pytest/issues/2908>`_: ``DeprecationWarning`` and ``PendingDeprecationWarning`` are now shown by default if no other warning filter is
configured. This makes pytest more compliant with
`PEP-0506 <https://www.python.org/dev/peps/pep-0565/#recommended-filter-settings-for-test-runners>`_. See
`the docs <https://docs.pytest.org/en/latest/warnings.html#deprecationwarning-and-pendingdeprecationwarning>`_ for
more info.
- `#3251 <https://github.com/pytest-dev/pytest/issues/3251>`_: Warnings are now captured and displayed during test collection.
- `#3784 <https://github.com/pytest-dev/pytest/issues/3784>`_: ``PYTEST_DISABLE_PLUGIN_AUTOLOAD`` environment variable disables plugin auto-loading when set.
- `#3829 <https://github.com/pytest-dev/pytest/issues/3829>`_: Added the ``count`` option to ``console_output_style`` to enable displaying the progress as a count instead of a percentage.
- `#3837 <https://github.com/pytest-dev/pytest/issues/3837>`_: Added support for 'xfailed' and 'xpassed' outcomes to the ``pytester.RunResult.assert_outcomes`` signature.
Bug Fixes
---------
- `#3911 <https://github.com/pytest-dev/pytest/issues/3911>`_: Terminal writer now takes into account unicode character width when writing out progress.
- `#3913 <https://github.com/pytest-dev/pytest/issues/3913>`_: Pytest now returns with correct exit code (EXIT_USAGEERROR, 4) when called with unknown arguments.
- `#3918 <https://github.com/pytest-dev/pytest/issues/3918>`_: Improve performance of assertion rewriting.
Improved Documentation
----------------------
- `#3566 <https://github.com/pytest-dev/pytest/issues/3566>`_: Added a blurb in usage.rst for the usage of -r flag which is used to show an extra test summary info.
- `#3907 <https://github.com/pytest-dev/pytest/issues/3907>`_: Corrected type of the exceptions collection passed to ``xfail``: ``raises`` argument accepts a ``tuple`` instead of ``list``.
Trivial/Internal Changes
------------------------
- `#3853 <https://github.com/pytest-dev/pytest/issues/3853>`_: Removed ``"run all (no recorded failures)"`` message printed with ``--failed-first`` and ``--last-failed`` when there are no failed tests.
pytest 3.7.4 (2018-08-29)
=========================
Bug Fixes
---------
- `#3506 <https://github.com/pytest-dev/pytest/issues/3506>`_: Fix possible infinite recursion when writing ``.pyc`` files.
- `#3853 <https://github.com/pytest-dev/pytest/issues/3853>`_: Cache plugin now obeys the ``-q`` flag when ``--last-failed`` and ``--failed-first`` flags are used.
- `#3883 <https://github.com/pytest-dev/pytest/issues/3883>`_: Fix bad console output when using ``console_output_style=classic``.
- `#3888 <https://github.com/pytest-dev/pytest/issues/3888>`_: Fix macOS specific code using ``capturemanager`` plugin in doctests.
Improved Documentation
----------------------
- `#3902 <https://github.com/pytest-dev/pytest/issues/3902>`_: Fix pytest.org links
pytest 3.7.3 (2018-08-26)
=========================
Bug Fixes
---------
- `#3033 <https://github.com/pytest-dev/pytest/issues/3033>`_: Fixtures during teardown can again use ``capsys`` and ``capfd`` to inspect output captured during tests.
- `#3773 <https://github.com/pytest-dev/pytest/issues/3773>`_: Fix collection of tests from ``__init__.py`` files if they match the ``python_files`` configuration option.
- `#3796 <https://github.com/pytest-dev/pytest/issues/3796>`_: Fix issue where teardown of fixtures of consecutive sub-packages were executed once, at the end of the outer
package.
- `#3816 <https://github.com/pytest-dev/pytest/issues/3816>`_: Fix bug where ``--show-capture=no`` option would still show logs printed during fixture teardown.
- `#3819 <https://github.com/pytest-dev/pytest/issues/3819>`_: Fix ``stdout/stderr`` not getting captured when real-time cli logging is active.
- `#3843 <https://github.com/pytest-dev/pytest/issues/3843>`_: Fix collection error when specifying test functions directly in the command line using ``test.py::test`` syntax together with ``--doctest-modules``.
- `#3848 <https://github.com/pytest-dev/pytest/issues/3848>`_: Fix bugs where unicode arguments could not be passed to ``testdir.runpytest`` on Python 2.
- `#3854 <https://github.com/pytest-dev/pytest/issues/3854>`_: Fix double collection of tests within packages when the filename starts with a capital letter.
Improved Documentation
----------------------
- `#3824 <https://github.com/pytest-dev/pytest/issues/3824>`_: Added example for multiple glob pattern matches in ``python_files``.
- `#3833 <https://github.com/pytest-dev/pytest/issues/3833>`_: Added missing docs for ``pytester.Testdir``.
- `#3870 <https://github.com/pytest-dev/pytest/issues/3870>`_: Correct documentation for setuptools integration.
Trivial/Internal Changes
------------------------
- `#3826 <https://github.com/pytest-dev/pytest/issues/3826>`_: Replace broken type annotations with type comments.
- `#3845 <https://github.com/pytest-dev/pytest/issues/3845>`_: Remove a reference to issue `#568 <https://github.com/pytest-dev/pytest/issues/568>`_ from the documentation, which has since been
fixed.
pytest 3.7.2 (2018-08-16)
=========================
Bug Fixes
---------
- `#3671 <https://github.com/pytest-dev/pytest/issues/3671>`_: Fix ``filterwarnings`` not being registered as a builtin mark.
- `#3768 <https://github.com/pytest-dev/pytest/issues/3768>`_, `#3789 <https://github.com/pytest-dev/pytest/issues/3789>`_: Fix test collection from packages mixed with normal directories.
- `#3771 <https://github.com/pytest-dev/pytest/issues/3771>`_: Fix infinite recursion during collection if a ``pytest_ignore_collect`` hook returns ``False`` instead of ``None``.
- `#3774 <https://github.com/pytest-dev/pytest/issues/3774>`_: Fix bug where decorated fixtures would lose functionality (for example ``@mock.patch``).
- `#3775 <https://github.com/pytest-dev/pytest/issues/3775>`_: Fix bug where importing modules or other objects with prefix ``pytest_`` prefix would raise a ``PluginValidationError``.
- `#3788 <https://github.com/pytest-dev/pytest/issues/3788>`_: Fix ``AttributeError`` during teardown of ``TestCase`` subclasses which raise an exception during ``__init__``.
- `#3804 <https://github.com/pytest-dev/pytest/issues/3804>`_: Fix traceback reporting for exceptions with ``__cause__`` cycles.
Improved Documentation
----------------------
- `#3746 <https://github.com/pytest-dev/pytest/issues/3746>`_: Add documentation for ``metafunc.config`` that had been mistakenly hidden.
pytest 3.7.1 (2018-08-02)
=========================
Bug Fixes
---------
- `#3473 <https://github.com/pytest-dev/pytest/issues/3473>`_: Raise immediately if ``approx()`` is given an expected value of a type it doesn't understand (e.g. strings, nested dicts, etc.).
- `#3712 <https://github.com/pytest-dev/pytest/issues/3712>`_: Correctly represent the dimensions of an numpy array when calling ``repr()`` on ``approx()``.
- `#3742 <https://github.com/pytest-dev/pytest/issues/3742>`_: Fix incompatibility with third party plugins during collection, which produced the error ``object has no attribute '_collectfile'``.
- `#3745 <https://github.com/pytest-dev/pytest/issues/3745>`_: Display the absolute path if ``cache_dir`` is not relative to the ``rootdir`` instead of failing.
- `#3747 <https://github.com/pytest-dev/pytest/issues/3747>`_: Fix compatibility problem with plugins and the warning code issued by fixture functions when they are called directly.
- `#3748 <https://github.com/pytest-dev/pytest/issues/3748>`_: Fix infinite recursion in ``pytest.approx`` with arrays in ``numpy<1.13``.
- `#3757 <https://github.com/pytest-dev/pytest/issues/3757>`_: Pin pathlib2 to ``>=2.2.0`` as we require ``__fspath__`` support.
- `#3763 <https://github.com/pytest-dev/pytest/issues/3763>`_: Fix ``TypeError`` when the assertion message is ``bytes`` in python 3.
pytest 3.7.0 (2018-07-30)
=========================
Deprecations and Removals
-------------------------
- `#2639 <https://github.com/pytest-dev/pytest/issues/2639>`_: ``pytest_namespace`` has been `deprecated <https://docs.pytest.org/en/latest/deprecations.html#pytest-namespace>`_.
- `#3661 <https://github.com/pytest-dev/pytest/issues/3661>`_: Calling a fixture function directly, as opposed to request them in a test function, now issues a ``RemovedInPytest4Warning``. See `the documentation for rationale and examples <https://docs.pytest.org/en/latest/deprecations.html#calling-fixtures-directly>`_.
Features
--------
- `#2283 <https://github.com/pytest-dev/pytest/issues/2283>`_: New ``package`` fixture scope: fixtures are finalized when the last test of a *package* finishes. This feature is considered **experimental**, so use it sparingly.
- `#3576 <https://github.com/pytest-dev/pytest/issues/3576>`_: ``Node.add_marker`` now supports an ``append=True/False`` parameter to determine whether the mark comes last (default) or first.
- `#3579 <https://github.com/pytest-dev/pytest/issues/3579>`_: Fixture ``caplog`` now has a ``messages`` property, providing convenient access to the format-interpolated log messages without the extra data provided by the formatter/handler.
- `#3610 <https://github.com/pytest-dev/pytest/issues/3610>`_: New ``--trace`` option to enter the debugger at the start of a test.
- `#3623 <https://github.com/pytest-dev/pytest/issues/3623>`_: Introduce ``pytester.copy_example`` as helper to do acceptance tests against examples from the project.
Bug Fixes
---------
- `#2220 <https://github.com/pytest-dev/pytest/issues/2220>`_: Fix a bug where fixtures overridden by direct parameters (for example parametrization) were being instantiated even if they were not being used by a test.
- `#3695 <https://github.com/pytest-dev/pytest/issues/3695>`_: Fix ``ApproxNumpy`` initialisation argument mixup, ``abs`` and ``rel`` tolerances were flipped causing strange comparsion results.
Add tests to check ``abs`` and ``rel`` tolerances for ``np.array`` and test for expecting ``nan`` with ``np.array()``
- `#980 <https://github.com/pytest-dev/pytest/issues/980>`_: Fix truncated locals output in verbose mode.
Improved Documentation
----------------------
- `#3295 <https://github.com/pytest-dev/pytest/issues/3295>`_: Correct the usage documentation of ``--last-failed-no-failures`` by adding the missing ``--last-failed`` argument in the presented examples, because they are misleading and lead to think that the missing argument is not needed.
Trivial/Internal Changes
------------------------
- `#3519 <https://github.com/pytest-dev/pytest/issues/3519>`_: Now a ``README.md`` file is created in ``.pytest_cache`` to make it clear why the directory exists.
pytest 3.6.4 (2018-07-28)
=========================
@@ -35,7 +420,7 @@ Trivial/Internal Changes
- Pin ``pluggy`` to ``<0.8``. (`#3727 <https://github.com/pytest-dev/pytest/issues/3727>`_)
Pytest 3.6.3 (2018-07-04)
pytest 3.6.3 (2018-07-04)
=========================
Bug Fixes
@@ -81,7 +466,7 @@ Trivial/Internal Changes
<https://github.com/pytest-dev/pytest/issues/3653>`_)
Pytest 3.6.2 (2018-06-20)
pytest 3.6.2 (2018-06-20)
=========================
Bug Fixes
@@ -127,7 +512,7 @@ Trivial/Internal Changes
<https://github.com/pytest-dev/pytest/issues/3567>`_)
Pytest 3.6.1 (2018-06-05)
pytest 3.6.1 (2018-06-05)
=========================
Bug Fixes
@@ -171,7 +556,7 @@ Trivial/Internal Changes
<https://github.com/pytest-dev/pytest/issues/3529>`_)
Pytest 3.6.0 (2018-05-23)
pytest 3.6.0 (2018-05-23)
=========================
Features
@@ -257,7 +642,7 @@ Trivial/Internal Changes
3.7 or newer. (`#3497 <https://github.com/pytest-dev/pytest/issues/3497>`_)
Pytest 3.5.1 (2018-04-23)
pytest 3.5.1 (2018-04-23)
=========================
@@ -309,7 +694,7 @@ Trivial/Internal Changes
<https://github.com/pytest-dev/pytest/issues/3398>`_)
Pytest 3.5.0 (2018-03-21)
pytest 3.5.0 (2018-03-21)
=========================
Deprecations and Removals
@@ -320,7 +705,7 @@ Deprecations and Removals
<https://github.com/pytest-dev/pytest/issues/2770>`_)
- Defining ``pytest_plugins`` is now deprecated in non-top-level conftest.py
files, because they "leak" to the entire directory tree. (`#3084
files, because they "leak" to the entire directory tree. `See the docs <https://docs.pytest.org/en/latest/deprecations.html#pytest-plugins-in-non-top-level-conftest-files>`_ for the rationale behind this decision (`#3084
<https://github.com/pytest-dev/pytest/issues/3084>`_)
@@ -461,7 +846,7 @@ Trivial/Internal Changes
<https://github.com/pytest-dev/pytest/issues/3308>`_)
Pytest 3.4.2 (2018-03-04)
pytest 3.4.2 (2018-03-04)
=========================
Bug Fixes
@@ -498,7 +883,7 @@ Trivial/Internal Changes
<https://github.com/pytest-dev/pytest/issues/3259>`_)
Pytest 3.4.1 (2018-02-20)
pytest 3.4.1 (2018-02-20)
=========================
Bug Fixes
@@ -559,7 +944,7 @@ Trivial/Internal Changes
<https://github.com/pytest-dev/pytest/issues/985>`_)
Pytest 3.4.0 (2018-01-30)
pytest 3.4.0 (2018-01-30)
=========================
Deprecations and Removals
@@ -691,7 +1076,7 @@ Trivial/Internal Changes
<https://github.com/pytest-dev/pytest/issues/3129>`_)
Pytest 3.3.2 (2017-12-25)
pytest 3.3.2 (2017-12-25)
=========================
Bug Fixes
@@ -728,7 +1113,7 @@ Trivial/Internal Changes
(`#3018 <https://github.com/pytest-dev/pytest/issues/3018>`_)
Pytest 3.3.1 (2017-12-05)
pytest 3.3.1 (2017-12-05)
=========================
Bug Fixes
@@ -770,13 +1155,13 @@ Trivial/Internal Changes
<https://github.com/pytest-dev/pytest/issues/2949>`_)
Pytest 3.3.0 (2017-11-23)
pytest 3.3.0 (2017-11-23)
=========================
Deprecations and Removals
-------------------------
- Pytest no longer supports Python **2.6** and **3.3**. Those Python versions
- pytest no longer supports Python **2.6** and **3.3**. Those Python versions
are EOL for some time now and incur maintenance and compatibility costs on
the pytest core team, and following up with the rest of the community we
decided that they will no longer be supported starting on this version. Users
@@ -830,7 +1215,7 @@ Features
- Match ``warns`` signature to ``raises`` by adding ``match`` keyword. (`#2708
<https://github.com/pytest-dev/pytest/issues/2708>`_)
- Pytest now captures and displays output from the standard ``logging`` module.
- pytest now captures and displays output from the standard ``logging`` module.
The user can control the logging level to be captured by specifying options
in ``pytest.ini``, the command line and also during individual tests using
markers. Also, a ``caplog`` fixture is available that enables users to test
@@ -895,7 +1280,7 @@ Bug Fixes
avoids a number of potential problems. (`#2751
<https://github.com/pytest-dev/pytest/issues/2751>`_)
- Pytest no longer complains about warnings with unicode messages being
- pytest no longer complains about warnings with unicode messages being
non-ascii compatible even for ascii-compatible messages. As a result of this,
warnings with unicode messages are converted first to an ascii representation
for safety. (`#2809 <https://github.com/pytest-dev/pytest/issues/2809>`_)
@@ -947,7 +1332,7 @@ Trivial/Internal Changes
<https://github.com/pytest-dev/pytest/issues/2922>`_)
Pytest 3.2.5 (2017-11-15)
pytest 3.2.5 (2017-11-15)
=========================
Bug Fixes
@@ -958,7 +1343,7 @@ Bug Fixes
<https://github.com/pytest-dev/pytest/issues/2926>`_)
Pytest 3.2.4 (2017-11-13)
pytest 3.2.4 (2017-11-13)
=========================
Bug Fixes
@@ -1007,7 +1392,7 @@ Improved Documentation
<https://github.com/pytest-dev/pytest/issues/911>`_)
Pytest 3.2.3 (2017-10-03)
pytest 3.2.3 (2017-10-03)
=========================
Bug Fixes
@@ -1047,7 +1432,7 @@ Trivial/Internal Changes
(`#2765 <https://github.com/pytest-dev/pytest/issues/2765>`_)
Pytest 3.2.2 (2017-09-06)
pytest 3.2.2 (2017-09-06)
=========================
Bug Fixes
@@ -1094,7 +1479,7 @@ Trivial/Internal Changes
<https://github.com/pytest-dev/pytest/issues/2739>`_)
Pytest 3.2.1 (2017-08-08)
pytest 3.2.1 (2017-08-08)
=========================
Bug Fixes
@@ -1124,7 +1509,7 @@ Improved Documentation
<https://github.com/pytest-dev/pytest/issues/2626>`_)
Pytest 3.2.0 (2017-07-30)
pytest 3.2.0 (2017-07-30)
=========================
Deprecations and Removals
@@ -1290,7 +1675,7 @@ Trivial/Internal Changes
<https://github.com/pytest-dev/pytest/issues/2620>`_)
Pytest 3.1.3 (2017-07-03)
pytest 3.1.3 (2017-07-03)
=========================
Bug Fixes
@@ -1336,7 +1721,7 @@ Trivial/Internal Changes
(`#2499 <https://github.com/pytest-dev/pytest/issues/2499>`_)
Pytest 3.1.2 (2017-06-08)
pytest 3.1.2 (2017-06-08)
=========================
Bug Fixes
@@ -1368,7 +1753,7 @@ Improved Documentation
and improve overall flow of the ``skipping`` docs. (#810)
Pytest 3.1.1 (2017-05-30)
pytest 3.1.1 (2017-05-30)
=========================
Bug Fixes

View File

@@ -28,10 +28,13 @@ taking a lot of time to make a new one.
#. After all tests pass and the PR has been approved, publish to PyPI by pushing the tag::
git tag <VERSION>
git push git@github.com:pytest-dev/pytest.git <VERSION>
Wait for the deploy to complete, then make sure it is `available on PyPI <https://pypi.org/project/pytest>`_.
#. Merge the PR into ``master``.
#. Send an email announcement with the contents from::
doc/en/announce/release-<VERSION>.rst

View File

@@ -1,5 +1,5 @@
.. image:: http://docs.pytest.org/en/latest/_static/pytest1.png
:target: http://docs.pytest.org
.. image:: https://docs.pytest.org/en/latest/_static/pytest1.png
:target: https://docs.pytest.org/en/latest/
:align: center
:alt: pytest
@@ -15,8 +15,9 @@
.. image:: https://img.shields.io/pypi/pyversions/pytest.svg
:target: https://pypi.org/project/pytest/
.. image:: https://img.shields.io/coveralls/pytest-dev/pytest/master.svg
:target: https://coveralls.io/r/pytest-dev/pytest
.. image:: https://codecov.io/gh/pytest-dev/pytest/branch/master/graph/badge.svg
:target: https://codecov.io/gh/pytest-dev/pytest
:alt: Code coverage Status
.. image:: https://travis-ci.org/pytest-dev/pytest.svg?branch=master
:target: https://travis-ci.org/pytest-dev/pytest
@@ -25,7 +26,7 @@
:target: https://ci.appveyor.com/project/pytestbot/pytest
.. image:: https://img.shields.io/badge/code%20style-black-000000.svg
:target: https://github.com/ambv/black
:target: https://github.com/ambv/black
.. image:: https://www.codetriage.com/pytest-dev/pytest/badges/users.svg
:target: https://www.codetriage.com/pytest-dev/pytest
@@ -66,23 +67,23 @@ To execute it::
========================== 1 failed in 0.04 seconds ===========================
Due to ``pytest``'s detailed assertion introspection, only plain ``assert`` statements are used. See `getting-started <http://docs.pytest.org/en/latest/getting-started.html#our-first-test-run>`_ for more examples.
Due to ``pytest``'s detailed assertion introspection, only plain ``assert`` statements are used. See `getting-started <https://docs.pytest.org/en/latest/getting-started.html#our-first-test-run>`_ for more examples.
Features
--------
- Detailed info on failing `assert statements <http://docs.pytest.org/en/latest/assert.html>`_ (no need to remember ``self.assert*`` names);
- Detailed info on failing `assert statements <https://docs.pytest.org/en/latest/assert.html>`_ (no need to remember ``self.assert*`` names);
- `Auto-discovery
<http://docs.pytest.org/en/latest/goodpractices.html#python-test-discovery>`_
<https://docs.pytest.org/en/latest/goodpractices.html#python-test-discovery>`_
of test modules and functions;
- `Modular fixtures <http://docs.pytest.org/en/latest/fixture.html>`_ for
- `Modular fixtures <https://docs.pytest.org/en/latest/fixture.html>`_ for
managing small or parametrized long-lived test resources;
- Can run `unittest <http://docs.pytest.org/en/latest/unittest.html>`_ (or trial),
`nose <http://docs.pytest.org/en/latest/nose.html>`_ test suites out of the box;
- Can run `unittest <https://docs.pytest.org/en/latest/unittest.html>`_ (or trial),
`nose <https://docs.pytest.org/en/latest/nose.html>`_ test suites out of the box;
- Python 2.7, Python 3.4+, PyPy 2.3, Jython 2.5 (untested);
@@ -92,7 +93,7 @@ Features
Documentation
-------------
For full documentation, including installation, tutorials and PDF documents, please see http://docs.pytest.org.
For full documentation, including installation, tutorials and PDF documents, please see https://docs.pytest.org/en/latest/.
Bugs/Requests
@@ -104,7 +105,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 <https://docs.pytest.org/en/latest/changelog.html>`__ page for fixes and enhancements of each version.
License

View File

@@ -1,34 +1,30 @@
environment:
COVERALLS_REPO_TOKEN:
secure: 2NJ5Ct55cHJ9WEg3xbSqCuv0rdgzzb6pnzOIG5OkMbTndw3wOBrXntWFoQrXiMFi
# this is pytest's token in coveralls.io, encrypted
# using pytestbot account as detailed here:
# https://www.appveyor.com/docs/build-configuration#secure-variables
matrix:
# coveralls is not in the default env list
- TOXENV: "coveralls"
# note: please use "tox --listenvs" to populate the build matrix below
- TOXENV: "linting"
PYTEST_NO_COVERAGE: "1"
- TOXENV: "py27"
- TOXENV: "py34"
- TOXENV: "py35"
- TOXENV: "py36"
- TOXENV: "py37"
- TOXENV: "pypy"
- TOXENV: "py27-pexpect"
PYTEST_NO_COVERAGE: "1"
- TOXENV: "py27-xdist"
- TOXENV: "py27-trial"
- TOXENV: "py27-numpy"
- TOXENV: "py27-pluggymaster"
- TOXENV: "py36-pexpect"
PYTEST_NO_COVERAGE: "1"
- TOXENV: "py36-xdist"
- TOXENV: "py36-trial"
- TOXENV: "py36-numpy"
- TOXENV: "py36-pluggymaster"
PYTEST_NO_COVERAGE: "1"
- TOXENV: "py27-nobyte"
- TOXENV: "doctesting"
- TOXENV: "py36-freeze"
PYTEST_NO_COVERAGE: "1"
- TOXENV: "docs"
PYTEST_NO_COVERAGE: "1"
install:
- echo Installed Pythons
@@ -36,12 +32,19 @@ install:
- if "%TOXENV%" == "pypy" call scripts\install-pypy.bat
- C:\Python36\python -m pip install --upgrade pip
- C:\Python36\python -m pip install --upgrade --pre tox
build: false # Not a C# project, build stuff at the test step instead.
before_test:
- call scripts\prepare-coverage.bat
test_script:
- call scripts\call-tox.bat
- C:\Python36\python -m tox
on_success:
- call scripts\upload-coverage.bat
cache:
- '%LOCALAPPDATA%\pip\cache'

View File

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

View File

@@ -26,7 +26,7 @@ changelog using that instead.
If you are not sure what issue type to use, don't hesitate to ask in your PR.
Note that the ``towncrier`` tool will automatically
reflow your text, so it will work best if you stick to a single paragraph, but multiple sentences and links are OK
and encouraged. You can install ``towncrier`` and then run ``towncrier --draft``
``towncrier`` preserves multiple paragraphs and formatting (code blocks, lists, and so on), but for entries
other than ``features`` it is usually better to stick to a single paragraph to keep it concise. You can install
``towncrier`` and then run ``towncrier --draft``
if you want to get a preview of how your change will look in the final release notes.

View File

@@ -14,7 +14,7 @@
{% if definitions[category]['showcontent'] %}
{% for text, values in sections[section][category]|dictsort(by='value') %}
{% set issue_joiner = joiner(', ') %}
- {{ text }}{% if category != 'vendor' %} ({% for value in values|sort %}{{ issue_joiner() }}`{{ value }} <https://github.com/pytest-dev/pytest/issues/{{ value[1:] }}>`_{% endfor %}){% endif %}
- {% for value in values|sort %}{{ issue_joiner() }}`{{ value }} <https://github.com/pytest-dev/pytest/issues/{{ value[1:] }}>`_{% endfor %}: {{ text }}
{% endfor %}

View File

@@ -6,6 +6,14 @@ Release announcements
:maxdepth: 2
release-3.8.2
release-3.8.1
release-3.8.0
release-3.7.4
release-3.7.3
release-3.7.2
release-3.7.1
release-3.7.0
release-3.6.4
release-3.6.3
release-3.6.2

View File

@@ -0,0 +1,41 @@
pytest-3.7.0
=======================================
The pytest team is proud to announce the 3.7.0 release!
pytest is a mature Python testing tool with more than a 2000 tests
against itself, passing on many different interpreters and platforms.
This release contains a number of bugs fixes and improvements, so users are encouraged
to take a look at the CHANGELOG:
http://doc.pytest.org/en/latest/changelog.html
For complete documentation, please visit:
http://docs.pytest.org
As usual, you can upgrade from pypi via:
pip install -U pytest
Thanks to all who contributed to this release, among them:
* Alan
* Alan Brammer
* Ammar Najjar
* Anthony Sottile
* Bruno Oliveira
* Jeffrey Rackauckas
* Kale Kundert
* Ronny Pfannschmidt
* Serhii Mozghovyi
* Tadek Teleżyński
* Wil Cooley
* abrammer
* avirlrma
* turturica
Happy testing,
The Pytest Development Team

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -264,8 +264,12 @@ Advanced assertion introspection
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.
modules directly discovered by its test collection process, so **asserts in
supporting modules which are not themselves test modules will not be rewritten**.
You can manually enable assertion rewriting for an imported module by calling
`register_assert_rewrite <https://docs.pytest.org/en/latest/writing_plugins.html#assertion-rewriting>`_
before you import it (a good place to do that is in ``conftest.py``).
.. note::

View File

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

View File

@@ -162,8 +162,8 @@ When no tests failed in the last run, or when no cached ``lastfailed`` data was
found, ``pytest`` can be configured either to run all of the tests or no tests,
using the ``--last-failed-no-failures`` option, which takes one of the following values::
pytest --last-failed-no-failures all # run all tests (default behavior)
pytest --last-failed-no-failures none # run no tests and exit
pytest --last-failed --last-failed-no-failures all # run all tests (default behavior)
pytest --last-failed --last-failed-no-failures none # run no tests and exit
The new config.cache object
--------------------------------

View File

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

View File

@@ -329,7 +329,7 @@ texinfo_documents = [
# Example configuration for intersphinx: refer to the Python standard library.
intersphinx_mapping = {"python": ("http://docs.python.org/3", None)}
intersphinx_mapping = {"python": ("https://docs.python.org/3", None)}
def setup(app):

View File

@@ -39,6 +39,7 @@ Full pytest documentation
bash-completion
backwards-compatibility
deprecations
historical-notes
license
contributing

View File

@@ -32,7 +32,7 @@ Here's a summary what ``pytest`` uses ``rootdir`` for:
class name, function name and parametrization (if any).
* Is used by plugins as a stable location to store project/test run specific information;
for example, the internal :ref:`cache <cache>` plugin creates a ``.cache`` subdirectory
for example, the internal :ref:`cache <cache>` plugin creates a ``.pytest_cache`` subdirectory
in ``rootdir`` to store its cross-test run state.
Important to emphasize that ``rootdir`` is **NOT** used to modify ``sys.path``/``PYTHONPATH`` or

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

@@ -0,0 +1,325 @@
.. _deprecations:
Deprecations and Removals
=========================
This page lists all pytest features that are currently deprecated or have been removed in past major releases.
The objective is to give users a clear rationale why a certain feature has been removed, and what alternatives
should be used instead.
Deprecated Features
-------------------
Below is a complete list of all pytest features which are considered deprecated. Using those features will issue
:class:`_pytest.warning_types.PytestWarning` or subclasses, which can be filtered using
:ref:`standard warning filters <warnings>`.
``Config.warn`` and ``Node.warn``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.. deprecated:: 3.8
Those methods were part of the internal pytest warnings system, but since ``3.8`` pytest is using the builtin warning
system for its own warnings, so those two functions are now deprecated.
``Config.warn`` should be replaced by calls to the standard ``warnings.warn``, example:
.. code-block:: python
config.warn("C1", "some warning")
Becomes:
.. code-block:: python
warnings.warn(pytest.PytestWarning("some warning"))
``Node.warn`` now supports two signatures:
* ``node.warn(PytestWarning("some message"))``: is now the **recommended** way to call this function.
The warning instance must be a PytestWarning or subclass.
* ``node.warn("CI", "some message")``: this code/message form is now **deprecated** and should be converted to the warning instance form above.
``pytest_namespace``
~~~~~~~~~~~~~~~~~~~~
.. deprecated:: 3.7
This hook is deprecated because it greatly complicates the pytest internals regarding configuration and initialization, making some
bug fixes and refactorings impossible.
Example of usage:
.. code-block:: python
class MySymbol:
...
def pytest_namespace():
return {"my_symbol": MySymbol()}
Plugin authors relying on this hook should instead require that users now import the plugin modules directly (with an appropriate public API).
As a stopgap measure, plugin authors may still inject their names into pytest's namespace, usually during ``pytest_configure``:
.. code-block:: python
import pytest
def pytest_configure():
pytest.my_symbol = MySymbol()
Calling fixtures directly
~~~~~~~~~~~~~~~~~~~~~~~~~
.. deprecated:: 3.7
Calling a fixture function directly, as opposed to request them in a test function, is deprecated.
For example:
.. code-block:: python
@pytest.fixture
def cell():
return ...
@pytest.fixture
def full_cell():
cell = cell()
cell.make_full()
return cell
This is a great source of confusion to new users, which will often call the fixture functions and request them from test functions interchangeably, which breaks the fixture resolution model.
In those cases just request the function directly in the dependent fixture:
.. code-block:: python
@pytest.fixture
def cell():
return ...
@pytest.fixture
def full_cell(cell):
cell.make_full()
return cell
``Node.get_marker``
~~~~~~~~~~~~~~~~~~~
.. deprecated:: 3.6
As part of a large :ref:`marker-revamp`, :meth:`_pytest.nodes.Node.get_marker` is deprecated. See
:ref:`the documentation <update marker code>` on tips on how to update your code.
record_xml_property
~~~~~~~~~~~~~~~~~~~
.. deprecated:: 3.5
The ``record_xml_property`` fixture is now deprecated in favor of the more generic ``record_property``, which
can be used by other consumers (for example ``pytest-html``) to obtain custom information about the test run.
This is just a matter of renaming the fixture as the API is the same:
.. code-block:: python
def test_foo(record_xml_property):
...
Change to:
.. code-block:: python
def test_foo(record_property):
...
pytest_plugins in non-top-level conftest files
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.. deprecated:: 3.5
Defining ``pytest_plugins`` is now deprecated in non-top-level conftest.py
files because they will activate referenced plugins *globally*, which is surprising because for all other pytest
features ``conftest.py`` files are only *active* for tests at or below it.
Metafunc.addcall
~~~~~~~~~~~~~~~~
.. deprecated:: 3.3
:meth:`_pytest.python.Metafunc.addcall` was a precursor to the current parametrized mechanism. Users should use
:meth:`_pytest.python.Metafunc.parametrize` instead.
marks in ``pytest.mark.parametrize``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.. deprecated:: 3.2
Applying marks to values of a ``pytest.mark.parametrize`` call is now deprecated. For example:
.. code-block:: python
@pytest.mark.parametrize(
"a, b", [(3, 9), pytest.mark.xfail(reason="flaky")(6, 36), (10, 100)]
)
def test_foo(a, b):
...
This code applies the ``pytest.mark.xfail(reason="flaky")`` mark to the ``(6, 36)`` value of the above parametrization
call.
This was considered hard to read and understand, and also its implementation presented problems to the code preventing
further internal improvements in the marks architecture.
To update the code, use ``pytest.param``:
.. code-block:: python
@pytest.mark.parametrize(
"a, b",
[(3, 9), pytest.param((6, 36), marks=pytest.mark.xfail(reason="flaky")), (10, 100)],
)
def test_foo(a, b):
...
Passing command-line string to ``pytest.main()``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.. deprecated:: 3.0
Passing a command-line string to ``pytest.main()`` is deprecated:
.. code-block:: python
pytest.main("-v -s")
Pass a list instead:
.. code-block:: python
pytest.main(["-v", "-s"])
By passing a string, users expect that pytest will interpret that command-line using the shell rules they are working
on (for example ``bash`` or ``Powershell``), but this is very hard/impossible to do in a portable way.
``yield`` tests
~~~~~~~~~~~~~~~
.. deprecated:: 3.0
pytest supports ``yield``-style tests, where a test function actually ``yield`` functions and values
that are then turned into proper test methods. Example:
.. code-block:: python
def check(x, y):
assert x ** x == y
def test_squared():
yield check, 2, 4
yield check, 3, 9
This would result into two actual test functions being generated.
This form of test function doesn't support fixtures properly, and users should switch to ``pytest.mark.parametrize``:
.. code-block:: python
@pytest.mark.parametrize("x, y", [(2, 4), (3, 9)])
def test_squared():
assert x ** x == y
``pytest_funcarg__`` prefix
~~~~~~~~~~~~~~~~~~~~~~~~~~~
.. deprecated:: 3.0
In very early pytest versions fixtures could be defined using the ``pytest_funcarg__`` prefix:
.. code-block:: python
def pytest_funcarg__data():
return SomeData()
Switch over to the ``@pytest.fixture`` decorator:
.. code-block:: python
@pytest.fixture
def data():
return SomeData()
[pytest] section in setup.cfg files
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.. deprecated:: 3.0
``[pytest]`` sections in ``setup.cfg`` files should now be named ``[tool:pytest]``
to avoid conflicts with other distutils commands.
Result log (``--result-log``)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.. deprecated:: 3.0
The ``--resultlog`` command line option has been deprecated: it is little used
and there are more modern and better alternatives, for example `pytest-tap <https://tappy.readthedocs.io/en/latest/>`_.
Removed Features
----------------
As stated in our :ref:`backwards-compatibility` policy, deprecated features are removed only in major releases after
an appropriate period of deprecation has passed.
Reinterpretation mode (``--assert=reinterp``)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*Removed in version 3.0.*
Reinterpretation mode has now been removed and only plain and rewrite
mode are available, consequently the ``--assert=reinterp`` option is
no longer available. This also means files imported from plugins or
``conftest.py`` will not benefit from improved assertions by
default, you should use ``pytest.register_assert_rewrite()`` to
explicitly turn on assertion rewriting for those files.
Removed command-line options
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*Removed in version 3.0.*
The following deprecated commandline options were removed:
* ``--genscript``: no longer supported;
* ``--no-assert``: use ``--assert=plain`` instead;
* ``--nomagic``: use ``--assert=plain`` instead;
* ``--report``: use ``-r`` instead;
py.test-X* entry points
~~~~~~~~~~~~~~~~~~~~~~~
*Removed in version 3.0.*
Removed all ``py.test-X*`` entry points. The versioned, suffixed entry points
were never documented and a leftover from a pre-virtualenv era. These entry
points also created broken entry points in wheels, so removing them also
removes a source of confusion for users.

View File

@@ -1,6 +1,6 @@
from pytest import raises
import _pytest._code
import py
import six
def otherfunc(a, b):
@@ -177,7 +177,7 @@ def test_dynamic_compile_shows_nicely():
name = "abc-123"
module = imp.new_module(name)
code = _pytest._code.compile(src, name, "exec")
py.builtin.exec_(code, module.__dict__)
six.exec_(code, module.__dict__)
sys.modules[name] = module
module.foo()

View File

@@ -10,4 +10,4 @@ def pytest_runtest_setup(item):
return
mod = item.getparent(pytest.Module).obj
if hasattr(mod, "hello"):
print("mod.hello %r" % (mod.hello,))
print("mod.hello {!r}".format(mod.hello))

View File

@@ -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.x.y, pytest-3.x.y, py-1.x.y, pluggy-0.x.y -- $PYTHON_PREFIX/bin/python3.5
platform linux -- Python 3.x.y, pytest-3.x.y, py-1.x.y, pluggy-0.x.y -- $PYTHON_PREFIX/bin/python
cachedir: .pytest_cache
rootdir: $REGENDOC_TMPDIR, inifile:
collecting ... collected 4 items / 3 deselected
@@ -44,7 +44,7 @@ Or the inverse, running all tests except the webtest ones::
$ pytest -v -m "not webtest"
=========================== test session starts ============================
platform linux -- Python 3.x.y, pytest-3.x.y, py-1.x.y, pluggy-0.x.y -- $PYTHON_PREFIX/bin/python3.5
platform linux -- Python 3.x.y, pytest-3.x.y, py-1.x.y, pluggy-0.x.y -- $PYTHON_PREFIX/bin/python
cachedir: .pytest_cache
rootdir: $REGENDOC_TMPDIR, inifile:
collecting ... collected 4 items / 1 deselected
@@ -64,7 +64,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.x.y, pytest-3.x.y, py-1.x.y, pluggy-0.x.y -- $PYTHON_PREFIX/bin/python3.5
platform linux -- Python 3.x.y, pytest-3.x.y, py-1.x.y, pluggy-0.x.y -- $PYTHON_PREFIX/bin/python
cachedir: .pytest_cache
rootdir: $REGENDOC_TMPDIR, inifile:
collecting ... collected 1 item
@@ -77,7 +77,7 @@ You can also select on the class::
$ pytest -v test_server.py::TestClass
=========================== test session starts ============================
platform linux -- Python 3.x.y, pytest-3.x.y, py-1.x.y, pluggy-0.x.y -- $PYTHON_PREFIX/bin/python3.5
platform linux -- Python 3.x.y, pytest-3.x.y, py-1.x.y, pluggy-0.x.y -- $PYTHON_PREFIX/bin/python
cachedir: .pytest_cache
rootdir: $REGENDOC_TMPDIR, inifile:
collecting ... collected 1 item
@@ -90,7 +90,7 @@ Or select multiple nodes::
$ pytest -v test_server.py::TestClass test_server.py::test_send_http
=========================== test session starts ============================
platform linux -- Python 3.x.y, pytest-3.x.y, py-1.x.y, pluggy-0.x.y -- $PYTHON_PREFIX/bin/python3.5
platform linux -- Python 3.x.y, pytest-3.x.y, py-1.x.y, pluggy-0.x.y -- $PYTHON_PREFIX/bin/python
cachedir: .pytest_cache
rootdir: $REGENDOC_TMPDIR, inifile:
collecting ... collected 2 items
@@ -128,7 +128,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.x.y, pytest-3.x.y, py-1.x.y, pluggy-0.x.y -- $PYTHON_PREFIX/bin/python3.5
platform linux -- Python 3.x.y, pytest-3.x.y, py-1.x.y, pluggy-0.x.y -- $PYTHON_PREFIX/bin/python
cachedir: .pytest_cache
rootdir: $REGENDOC_TMPDIR, inifile:
collecting ... collected 4 items / 3 deselected
@@ -141,7 +141,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.x.y, pytest-3.x.y, py-1.x.y, pluggy-0.x.y -- $PYTHON_PREFIX/bin/python3.5
platform linux -- Python 3.x.y, pytest-3.x.y, py-1.x.y, pluggy-0.x.y -- $PYTHON_PREFIX/bin/python
cachedir: .pytest_cache
rootdir: $REGENDOC_TMPDIR, inifile:
collecting ... collected 4 items / 1 deselected
@@ -156,7 +156,7 @@ Or to select "http" and "quick" tests::
$ pytest -k "http or quick" -v
=========================== test session starts ============================
platform linux -- Python 3.x.y, pytest-3.x.y, py-1.x.y, pluggy-0.x.y -- $PYTHON_PREFIX/bin/python3.5
platform linux -- Python 3.x.y, pytest-3.x.y, py-1.x.y, pluggy-0.x.y -- $PYTHON_PREFIX/bin/python
cachedir: .pytest_cache
rootdir: $REGENDOC_TMPDIR, inifile:
collecting ... collected 4 items / 2 deselected
@@ -200,15 +200,17 @@ You can ask which markers exist for your test suite - the list includes our just
$ pytest --markers
@pytest.mark.webtest: mark a test as a webtest.
@pytest.mark.filterwarnings(warning): add a warning filter to the given test. see https://docs.pytest.org/en/latest/warnings.html#pytest-mark-filterwarnings
@pytest.mark.skip(reason=None): skip the given test function with an optional reason. Example: skip(reason="no way of currently testing this") skips the test.
@pytest.mark.skipif(condition): skip the given test function if eval(condition) results in a True value. Evaluation happens within the module global context. Example: skipif('sys.platform == "win32"') skips the test if we are on the win32 platform. see http://pytest.org/latest/skipping.html
@pytest.mark.skipif(condition): skip the given test function if eval(condition) results in a True value. Evaluation happens within the module global context. Example: skipif('sys.platform == "win32"') skips the test if we are on the win32 platform. see https://docs.pytest.org/en/latest/skipping.html
@pytest.mark.xfail(condition, reason=None, run=True, raises=None, strict=False): mark the test function as an expected failure if eval(condition) has a True value. Optionally specify a reason for better reporting and run=False if you don't even want to execute the test function. If only specific exception(s) are expected, you can list them in raises, and if the test fails in other ways, it will be reported as a true failure. See http://pytest.org/latest/skipping.html
@pytest.mark.xfail(condition, reason=None, run=True, raises=None, strict=False): mark the test function as an expected failure if eval(condition) has a True value. Optionally specify a reason for better reporting and run=False if you don't even want to execute the test function. If only specific exception(s) are expected, you can list them in raises, and if the test fails in other ways, it will be reported as a true failure. See https://docs.pytest.org/en/latest/skipping.html
@pytest.mark.parametrize(argnames, argvalues): call a test function multiple times passing in different arguments in turn. argvalues generally needs to be a list of values if argnames specifies only one name or a list of tuples of values if argnames specifies multiple names. Example: @parametrize('arg1', [1,2]) would lead to two calls of the decorated test function, one with arg1=1 and another with arg1=2.see http://pytest.org/latest/parametrize.html for more info and examples.
@pytest.mark.parametrize(argnames, argvalues): call a test function multiple times passing in different arguments in turn. argvalues generally needs to be a list of values if argnames specifies only one name or a list of tuples of values if argnames specifies multiple names. Example: @parametrize('arg1', [1,2]) would lead to two calls of the decorated test function, one with arg1=1 and another with arg1=2.see https://docs.pytest.org/en/latest/parametrize.html for more info and examples.
@pytest.mark.usefixtures(fixturename1, fixturename2, ...): mark tests as needing all of the specified fixtures. see http://pytest.org/latest/fixture.html#usefixtures
@pytest.mark.usefixtures(fixturename1, fixturename2, ...): mark tests as needing all of the specified fixtures. see https://docs.pytest.org/en/latest/fixture.html#usefixtures
@pytest.mark.tryfirst: mark a hook implementation function such that the plugin machinery will try to call it first/as early as possible.
@@ -374,15 +376,17 @@ The ``--markers`` option always gives you a list of available markers::
$ pytest --markers
@pytest.mark.env(name): mark test to run only on named environment
@pytest.mark.filterwarnings(warning): add a warning filter to the given test. see https://docs.pytest.org/en/latest/warnings.html#pytest-mark-filterwarnings
@pytest.mark.skip(reason=None): skip the given test function with an optional reason. Example: skip(reason="no way of currently testing this") skips the test.
@pytest.mark.skipif(condition): skip the given test function if eval(condition) results in a True value. Evaluation happens within the module global context. Example: skipif('sys.platform == "win32"') skips the test if we are on the win32 platform. see http://pytest.org/latest/skipping.html
@pytest.mark.skipif(condition): skip the given test function if eval(condition) results in a True value. Evaluation happens within the module global context. Example: skipif('sys.platform == "win32"') skips the test if we are on the win32 platform. see https://docs.pytest.org/en/latest/skipping.html
@pytest.mark.xfail(condition, reason=None, run=True, raises=None, strict=False): mark the test function as an expected failure if eval(condition) has a True value. Optionally specify a reason for better reporting and run=False if you don't even want to execute the test function. If only specific exception(s) are expected, you can list them in raises, and if the test fails in other ways, it will be reported as a true failure. See http://pytest.org/latest/skipping.html
@pytest.mark.xfail(condition, reason=None, run=True, raises=None, strict=False): mark the test function as an expected failure if eval(condition) has a True value. Optionally specify a reason for better reporting and run=False if you don't even want to execute the test function. If only specific exception(s) are expected, you can list them in raises, and if the test fails in other ways, it will be reported as a true failure. See https://docs.pytest.org/en/latest/skipping.html
@pytest.mark.parametrize(argnames, argvalues): call a test function multiple times passing in different arguments in turn. argvalues generally needs to be a list of values if argnames specifies only one name or a list of tuples of values if argnames specifies multiple names. Example: @parametrize('arg1', [1,2]) would lead to two calls of the decorated test function, one with arg1=1 and another with arg1=2.see http://pytest.org/latest/parametrize.html for more info and examples.
@pytest.mark.parametrize(argnames, argvalues): call a test function multiple times passing in different arguments in turn. argvalues generally needs to be a list of values if argnames specifies only one name or a list of tuples of values if argnames specifies multiple names. Example: @parametrize('arg1', [1,2]) would lead to two calls of the decorated test function, one with arg1=1 and another with arg1=2.see https://docs.pytest.org/en/latest/parametrize.html for more info and examples.
@pytest.mark.usefixtures(fixturename1, fixturename2, ...): mark tests as needing all of the specified fixtures. see http://pytest.org/latest/fixture.html#usefixtures
@pytest.mark.usefixtures(fixturename1, fixturename2, ...): mark tests as needing all of the specified fixtures. see https://docs.pytest.org/en/latest/fixture.html#usefixtures
@pytest.mark.tryfirst: mark a hook implementation function such that the plugin machinery will try to call it first/as early as possible.

View File

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

View File

@@ -59,7 +59,7 @@ consulted when reporting in ``verbose`` mode::
nonpython $ pytest -v
=========================== test session starts ============================
platform linux -- Python 3.x.y, pytest-3.x.y, py-1.x.y, pluggy-0.x.y -- $PYTHON_PREFIX/bin/python3.5
platform linux -- Python 3.x.y, pytest-3.x.y, py-1.x.y, pluggy-0.x.y -- $PYTHON_PREFIX/bin/python
cachedir: .pytest_cache
rootdir: $REGENDOC_TMPDIR/nonpython, inifile:
collecting ... collected 2 items
@@ -84,8 +84,9 @@ interesting to just look at the collection tree::
platform linux -- Python 3.x.y, pytest-3.x.y, py-1.x.y, pluggy-0.x.y
rootdir: $REGENDOC_TMPDIR/nonpython, inifile:
collected 2 items
<YamlFile 'test_simple.yml'>
<YamlItem 'hello'>
<YamlItem 'ok'>
<Package '$REGENDOC_TMPDIR/nonpython'>
<YamlFile 'test_simple.yml'>
<YamlItem 'hello'>
<YamlItem 'ok'>
======================= no tests ran in 0.12 seconds =======================

View File

@@ -413,7 +413,7 @@ Running it results in some skips if we don't have all the python interpreters in
. $ pytest -rs -q multipython.py
...sss...sssssssss...sss... [100%]
========================= short test summary info ==========================
SKIP [15] $REGENDOC_TMPDIR/CWD/multipython.py:28: 'python3.4' not found
SKIP [15] $REGENDOC_TMPDIR/CWD/multipython.py:29: 'python3.4' not found
12 passed, 15 skipped in 0.12 seconds
Indirect parametrization of optional implementations/imports

View File

@@ -100,19 +100,21 @@ Changing naming conventions
You can configure different naming conventions by setting
the :confval:`python_files`, :confval:`python_classes` and
:confval:`python_functions` configuration options. Example::
:confval:`python_functions` configuration options.
Here is an example::
# content of pytest.ini
# Example 1: have pytest look for "check" instead of "test"
# can also be defined in tox.ini or setup.cfg file, although the section
# name in setup.cfg files should be "tool:pytest"
[pytest]
python_files=check_*.py
python_classes=Check
python_functions=*_check
python_files = check_*.py
python_classes = Check
python_functions = *_check
This would make ``pytest`` look for tests in files that match the ``check_*
.py`` glob-pattern, ``Check`` prefixes in classes, and functions and methods
that match ``*_check``. For example, if we have::
that match ``*_check``. For example, if we have::
# content of check_myapp.py
class CheckMyApp(object):
@@ -121,7 +123,7 @@ that match ``*_check``. For example, if we have::
def complex_check(self):
pass
then the test collection looks like this::
The test collection would look like this::
$ pytest --collect-only
=========================== test session starts ============================
@@ -136,11 +138,19 @@ then the test collection looks like this::
======================= no tests ran in 0.12 seconds =======================
You can check for multiple glob patterns by adding a space between the patterns::
# Example 2: have pytest look for files with "test" and "example"
# content of pytest.ini, tox.ini, or setup.cfg file (replace "pytest"
# with "tool:pytest" for setup.cfg)
[pytest]
python_files = test_*.py example_*.py
.. note::
the ``python_functions`` and ``python_classes`` options has no effect
for ``unittest.TestCase`` test discovery because pytest delegates
detection of test case methods to unittest code.
discovery of test case methods to unittest code.
Interpreting cmdline arguments as Python packages
-----------------------------------------------------

View File

@@ -363,7 +363,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_api.py:635>:1: ValueError
<0-codegen $PYTHON_PREFIX/lib/python3.6/site-packages/_pytest/python_api.py:682>:1: ValueError
______________________ TestRaises.test_raises_doesnt _______________________
self = <failure_demo.TestRaises object at 0xdeadbeef>
@@ -423,7 +423,7 @@ get on the terminal - we are working on that)::
name = "abc-123"
module = imp.new_module(name)
code = _pytest._code.compile(src, name, "exec")
py.builtin.exec_(code, module.__dict__)
six.exec_(code, module.__dict__)
sys.modules[name] = module
> module.foo()
@@ -613,9 +613,9 @@ get on the terminal - we are working on that)::
failure_demo.py:261: AssertionError
============================= warnings summary =============================
<undetermined location>
Metafunc.addcall is deprecated and scheduled to be removed in pytest 4.0.
Please use Metafunc.parametrize instead.
$REGENDOC_TMPDIR/assertion/failure_demo.py:24: RemovedInPytest4Warning: Metafunc.addcall is deprecated and scheduled to be removed in pytest 4.0.
Please use Metafunc.parametrize instead.
metafunc.addcall(funcargs=dict(param1=3, param2=6))
-- Docs: http://doc.pytest.org/en/latest/warnings.html
-- Docs: https://docs.pytest.org/en/latest/warnings.html
================== 42 failed, 1 warnings in 0.12 seconds ===================

View File

@@ -357,7 +357,7 @@ which will add info only when run with "--v"::
$ pytest -v
=========================== test session starts ============================
platform linux -- Python 3.x.y, pytest-3.x.y, py-1.x.y, pluggy-0.x.y -- $PYTHON_PREFIX/bin/python3.5
platform linux -- Python 3.x.y, pytest-3.x.y, py-1.x.y, pluggy-0.x.y -- $PYTHON_PREFIX/bin/python
cachedir: .pytest_cache
info1: did you know that ...
did you?

View File

@@ -171,6 +171,7 @@ to cause the decorated ``smtp_connection`` fixture function to only be invoked
once per test *module* (the default is to invoke once per test *function*).
Multiple test functions in a test module will thus
each receive the same ``smtp_connection`` fixture instance, thus saving time.
Possible values for ``scope`` are: ``function``, ``class``, ``module``, ``package`` or ``session``.
The next example puts the fixture function into a separate ``conftest.py`` file
so that tests from multiple test modules in the directory can
@@ -259,6 +260,22 @@ instance, you can simply declare it:
Finally, the ``class`` scope will invoke the fixture once per test *class*.
``package`` scope (experimental)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.. versionadded:: 3.7
In pytest 3.7 the ``package`` scope has been introduced. Package-scoped fixtures
are finalized when the last test of a *package* finishes.
.. warning::
This functionality is considered **experimental** and may be removed in future
versions if hidden corner-cases or serious problems with this functionality
are discovered after it gets more usage in the wild.
Use this new feature sparingly and please make sure to report any issues you find.
Higher-scoped fixtures are instantiated first
---------------------------------------------
@@ -710,7 +727,7 @@ Running this test will *skip* the invocation of ``data_set`` with value ``2``::
$ pytest test_fixture_marks.py -v
=========================== test session starts ============================
platform linux -- Python 3.x.y, pytest-3.x.y, py-1.x.y, pluggy-0.x.y -- $PYTHON_PREFIX/bin/python3.5
platform linux -- Python 3.x.y, pytest-3.x.y, py-1.x.y, pluggy-0.x.y -- $PYTHON_PREFIX/bin/python
cachedir: .pytest_cache
rootdir: $REGENDOC_TMPDIR, inifile:
collecting ... collected 3 items
@@ -753,7 +770,7 @@ Here we declare an ``app`` fixture which receives the previously defined
$ pytest -v test_appsetup.py
=========================== test session starts ============================
platform linux -- Python 3.x.y, pytest-3.x.y, py-1.x.y, pluggy-0.x.y -- $PYTHON_PREFIX/bin/python3.5
platform linux -- Python 3.x.y, pytest-3.x.y, py-1.x.y, pluggy-0.x.y -- $PYTHON_PREFIX/bin/python
cachedir: .pytest_cache
rootdir: $REGENDOC_TMPDIR, inifile:
collecting ... collected 2 items
@@ -822,7 +839,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.x.y, pytest-3.x.y, py-1.x.y, pluggy-0.x.y -- $PYTHON_PREFIX/bin/python3.5
platform linux -- Python 3.x.y, pytest-3.x.y, py-1.x.y, pluggy-0.x.y -- $PYTHON_PREFIX/bin/python
cachedir: .pytest_cache
rootdir: $REGENDOC_TMPDIR, inifile:
collecting ... collected 8 items

View File

@@ -7,7 +7,7 @@ pytest-2.3: reasoning for fixture/funcarg evolution
**Target audience**: Reading this document requires basic knowledge of
python testing, xUnit setup methods and the (previous) basic pytest
funcarg mechanism, see http://pytest.org/2.2.4/funcargs.html
funcarg mechanism, see https://docs.pytest.org/en/latest/historical-notes.html#funcargs-and-pytest-funcarg.
If you are new to pytest, then you can simply ignore this
section and read the other sections.

View File

@@ -1,7 +1,7 @@
Installation and Getting Started
===================================
**Pythons**: Python 2.7, 3.4, 3.5, 3.6, Jython, PyPy-2.3
**Pythons**: Python 2.7, 3.4, 3.5, 3.6, 3.7, Jython, PyPy-2.3
**Platforms**: Unix/Posix and Windows
@@ -27,7 +27,7 @@ Install ``pytest``
2. Check that you installed the correct version::
$ pytest --version
This is pytest version 3.x.y, imported from $PYTHON_PREFIX/lib/python3.5/site-packages/pytest.py
This is pytest version 3.x.y, imported from $PYTHON_PREFIX/lib/python3.6/site-packages/pytest.py
.. _`simpletest`:

View File

@@ -4,6 +4,27 @@
Good Integration Practices
=================================================
Install package with pip
-------------------------------------------------
For development, we recommend to use virtualenv_ environments and pip_
for installing your application and any dependencies
as well as the ``pytest`` package itself. This ensures your code and
dependencies are isolated from the system Python installation.
First you need to place a ``setup.py`` file in the root of your package with the following minimum content::
from setuptools import setup, find_packages
setup(name="PACKAGENAME", packages=find_packages())
Where ``PACKAGENAME`` is the name of your package. You can then install your package in "editable" mode by running from the same directory::
pip install -e .
which lets you change your source code (both tests and application) and rerun tests at will.
This is similar to running ``python setup.py develop`` or ``conda develop`` in that it installs
your package using a symlink to your development code.
.. _`test discovery`:
.. _`Python test discovery`:
@@ -177,19 +198,6 @@ Note that this layout also works in conjunction with the ``src`` layout mentione
tox
------
For development, we recommend to use virtualenv_ environments and pip_
for installing your application and any dependencies
as well as the ``pytest`` package itself. This ensures your code and
dependencies are isolated from the system Python installation.
You can then install your package in "editable" mode::
pip install -e .
which lets you change your source code (both tests and application) and rerun tests at will.
This is similar to running ``python setup.py develop`` or ``conda develop`` in that it installs
your package using a symlink to your development code.
Once you are done with your work and want to make sure that your actual
package passes all tests you may want to look into `tox`_, the
virtualenv test automation tool and its `pytest support
@@ -282,7 +290,7 @@ your own setuptools Test command for invoking pytest.
setup(
# ...,
tests_require=["pytest"],
cmdclass={"test": PyTest},
cmdclass={"pytest": PyTest},
)
Now if you run::

View File

@@ -52,6 +52,8 @@ should add ``--strict`` to ``addopts``:
serial
.. _marker-revamp:
Marker revamp and iteration
---------------------------

View File

@@ -460,7 +460,7 @@ To use it, include in your top-most ``conftest.py`` file::
.. autoclass:: Testdir()
:members: runpytest,runpytest_subprocess,runpytest_inprocess,makeconftest,makepyfile
:members:
.. autoclass:: RunResult()
:members:
@@ -611,6 +611,8 @@ Session related reporting hooks:
.. autofunction:: pytest_terminal_summary
.. autofunction:: pytest_fixture_setup
.. autofunction:: pytest_fixture_post_finalizer
.. autofunction:: pytest_logwarning
.. autofunction:: pytest_warning_captured
And here is the central hook for reporting about
test execution:
@@ -787,7 +789,7 @@ TestReport
_Result
~~~~~~~
.. autoclass:: pluggy._Result
.. autoclass:: pluggy.callers._Result
:members:
Special Variables
@@ -866,6 +868,11 @@ Contains comma-separated list of modules that should be loaded as plugins:
export PYTEST_PLUGINS=mymodule.plugin,xdist
PYTEST_DISABLE_PLUGIN_AUTOLOAD
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
When set, disables plugin auto-loading through setuptools entrypoints. Only explicitly specified plugins will be
loaded.
PYTEST_CURRENT_TEST
~~~~~~~~~~~~~~~~~~~
@@ -935,6 +942,7 @@ passed multiple times. The expected format is ``name=value``. For example::
* ``classic``: classic pytest output.
* ``progress``: like classic pytest output, but with a progress indicator.
* ``count``: like progress, but shows progress as the number of tests completed instead of a percent.
The default is ``progress``, but you can fallback to ``classic`` if you prefer or
the new mode is causing unexpected problems:
@@ -1229,7 +1237,8 @@ passed multiple times. The expected format is ``name=value``. For example::
.. confval:: python_classes
One or more name prefixes or glob-style patterns determining which classes
are considered for test collection. By default, pytest will consider any
are considered for test collection. Search for multiple glob patterns by
adding a space between patterns. By default, pytest will consider any
class prefixed with ``Test`` as a test collection. Here is an example of how
to collect tests from classes that end in ``Suite``:
@@ -1246,15 +1255,33 @@ passed multiple times. The expected format is ``name=value``. For example::
.. confval:: python_files
One or more Glob-style file patterns determining which python files
are considered as test modules. By default, pytest will consider
any file matching with ``test_*.py`` and ``*_test.py`` globs as a test
module.
are considered as test modules. Search for multiple glob patterns by
adding a space between patterns:
.. code-block:: ini
[pytest]
python_files = test_*.py check_*.py example_*.py
Or one per line:
.. code-block:: ini
[pytest]
python_files =
test_*.py
check_*.py
example_*.py
By default, files matching ``test_*.py`` and ``*_test.py`` will be considered
test modules.
.. confval:: python_functions
One or more name prefixes or glob-patterns determining which test functions
and methods are considered tests. By default, pytest will consider any
and methods are considered tests. Search for multiple glob patterns by
adding a space between patterns. By default, pytest will consider any
function prefixed with ``test`` as a test. Here is an example of how
to collect test functions and methods that end in ``_test``:

View File

@@ -136,12 +136,6 @@ You can use the ``skipif`` marker (as any other marker) on classes::
If the condition is ``True``, this marker will produce a skip result for
each of the test methods of that class.
.. warning::
The use of ``skipif`` on classes that use inheritance is strongly
discouraged. `A Known bug <https://github.com/pytest-dev/pytest/issues/568>`_
in pytest's markers may cause unexpected behavior in super classes.
If you want to skip all test functions of a module, you may use
the ``pytestmark`` name on the global level:
@@ -283,7 +277,7 @@ on a particular platform::
~~~~~~~~~~~~~~~~~~~~
If you want to be more specific as to why the test is failing, you can specify
a single exception, or a list of exceptions, in the ``raises`` argument.
a single exception, or a tuple of exceptions, in the ``raises`` argument.
.. code-block:: python

View File

@@ -14,6 +14,9 @@ Talks and Tutorials
Books
---------------------------------------------
- `pytest Quick Start Guide, by Bruno Oliveira (2018)
<https://www.packtpub.com/web-development/pytest-quick-start-guide>`_.
- `Python Testing with pytest, by Brian Okken (2017)
<https://pragprog.com/book/bopytest/python-testing-with-pytest>`_.

View File

@@ -140,6 +140,49 @@ will be shown (because KeyboardInterrupt is caught by pytest). By using this
option you make sure a trace is shown.
.. _`pytest.detailed_failed_tests_usage`:
Detailed summary report
-----------------------
.. versionadded:: 2.9
The ``-r`` flag can be used to display test results summary at the end of the test session,
making it easy in large test suites to get a clear picture of all failures, skips, xfails, etc.
Example::
$ pytest -ra
=========================== test session starts ============================
platform linux -- Python 3.x.y, pytest-3.x.y, py-1.x.y, pluggy-0.x.y
rootdir: $REGENDOC_TMPDIR, inifile:
collected 0 items
======================= no tests ran in 0.12 seconds =======================
The ``-r`` options accepts a number of characters after it, with ``a`` used above meaning "all except passes".
Here is the full list of available characters that can be used:
- ``f`` - failed
- ``E`` - error
- ``s`` - skipped
- ``x`` - xfailed
- ``X`` - xpassed
- ``p`` - passed
- ``P`` - passed with output
- ``a`` - all except ``pP``
More than one character can be used, so for example to only see failed and skipped tests, you can execute::
$ pytest -rfs
=========================== test session starts ============================
platform linux -- Python 3.x.y, pytest-3.x.y, py-1.x.y, pluggy-0.x.y
rootdir: $REGENDOC_TMPDIR, inifile:
collected 0 items
======================= no tests ran in 0.12 seconds =======================
.. _pdb-option:
Dropping to PDB_ (Python Debugger) on failures
@@ -171,6 +214,18 @@ for example::
>>> sys.last_value
AssertionError('assert result == "ok"',)
.. _trace-option:
Dropping to PDB_ (Python Debugger) at the start of a test
----------------------------------------------------------
``pytest`` allows one to drop into the PDB_ prompt immediately at the start of each test via a command line option::
pytest --trace
This will invoke the Python debugger at the start of every test.
.. _breakpoints:
Setting breakpoints
@@ -200,7 +255,7 @@ Pytest supports the use of ``breakpoint()`` with the following behaviours:
- When ``breakpoint()`` is called and ``PYTHONBREAKPOINT`` is set to the default value, pytest will use the custom internal PDB trace UI instead of the system default ``Pdb``.
- When tests are complete, the system will default back to the system ``Pdb`` trace UI.
- If ``--pdb`` is called on execution of pytest, the custom internal Pdb trace UI is used on ``bothbreakpoint()`` and failed tests/unhandled exceptions.
- If ``--pdb`` is called on execution of pytest, the custom internal Pdb trace UI is used on both ``breakpoint()`` and failed tests/unhandled exceptions.
- If ``--pdbcls`` is used, the custom class debugger will be executed when a test fails (as expected within existing behaviour), but also when ``breakpoint()`` is called from within a test, the custom class debugger will be instantiated.
.. _durations:

View File

@@ -29,15 +29,12 @@ Running pytest now produces this output::
test_show_warnings.py . [100%]
============================= warnings summary =============================
test_show_warnings.py::test_one
$REGENDOC_TMPDIR/test_show_warnings.py:4: UserWarning: api v1, should use functions from v2
warnings.warn(UserWarning("api v1, should use functions from v2"))
$REGENDOC_TMPDIR/test_show_warnings.py:4: UserWarning: api v1, should use functions from v2
warnings.warn(UserWarning("api v1, should use functions from v2"))
-- Docs: http://doc.pytest.org/en/latest/warnings.html
-- Docs: https://docs.pytest.org/en/latest/warnings.html
=================== 1 passed, 1 warnings in 0.12 seconds ===================
Pytest by default catches all warnings except for ``DeprecationWarning`` and ``PendingDeprecationWarning``.
The ``-W`` flag can be passed to control which warnings will be displayed or even turn
them into errors::
@@ -78,6 +75,53 @@ Both ``-W`` command-line option and ``filterwarnings`` ini option are based on P
`-W option`_ and `warnings.simplefilter`_, so please refer to those sections in the Python
documentation for other examples and advanced usage.
Disabling warning summary
-------------------------
Although not recommended, you can use the ``--disable-warnings`` command-line option to suppress the
warning summary entirely from the test run output.
Disabling warning capture entirely
----------------------------------
This plugin is enabled by default but can be disabled entirely in your ``pytest.ini`` file with:
.. code-block:: ini
[pytest]
addopts = -p no:warnings
Or passing ``-p no:warnings`` in the command-line. This might be useful if your test suites handles warnings
using an external system.
.. _`deprecation-warnings`:
DeprecationWarning and PendingDeprecationWarning
------------------------------------------------
.. versionadded:: 3.8
By default pytest will display ``DeprecationWarning`` and ``PendingDeprecationWarning`` if no other warning filters
are configured.
To disable showing ``DeprecationWarning`` and ``PendingDeprecationWarning`` warnings, you might define any warnings
filter either in the command-line or in the ini file, or you can use:
.. code-block:: ini
[pytest]
filterwarnings =
ignore::DeprecationWarning
ignore::PendingDeprecationWarning
.. note::
This makes pytest more compliant with `PEP-0506 <https://www.python.org/dev/peps/pep-0565/#recommended-filter-settings-for-test-runners>`_ which suggests that those warnings should
be shown by default by test runners, but pytest doesn't follow ``PEP-0506`` completely because resetting all
warning filters like suggested in the PEP will break existing test suites that configure warning filters themselves
by calling ``warnings.simplefilter`` (see issue `#2430 <https://github.com/pytest-dev/pytest/issues/2430>`_
for an example of that).
.. _`filterwarnings`:
@@ -144,18 +188,6 @@ decorator or to all tests in a module by setting the ``pytestmark`` variable:
.. _`pytest-warnings`: https://github.com/fschulze/pytest-warnings
Disabling warning capture
-------------------------
This feature is enabled by default but can be disabled entirely in your ``pytest.ini`` file with:
.. code-block:: ini
[pytest]
addopts = -p no:warnings
Or passing ``-p no:warnings`` in the command-line.
.. _`asserting warnings`:
.. _assertwarnings:
@@ -296,3 +328,53 @@ You can also use it as a contextmanager::
def test_global():
with pytest.deprecated_call():
myobject.deprecated_method()
.. _internal-warnings:
Internal pytest warnings
------------------------
.. versionadded:: 3.8
pytest may generate its own warnings in some situations, such as improper usage or deprecated features.
For example, pytest will emit a warning if it encounters a class that matches :confval:`python_classes` but also
defines an ``__init__`` constructor, as this prevents the class from being instantiated:
.. code-block:: python
# content of test_pytest_warnings.py
class Test:
def __init__(self):
pass
def test_foo(self):
assert 1 == 1
::
$ pytest test_pytest_warnings.py -q
============================= warnings summary =============================
$REGENDOC_TMPDIR/test_pytest_warnings.py:1: PytestWarning: cannot collect test class 'Test' because it has a __init__ constructor
class Test:
-- Docs: https://docs.pytest.org/en/latest/warnings.html
1 warnings in 0.12 seconds
These warnings might be filtered using the same builtin mechanisms used to filter other types of warnings.
Please read our :ref:`backwards-compatibility` to learn how we proceed about deprecating and eventually removing
features.
The following warning types ares used by pytest and are part of the public API:
.. autoclass:: pytest.PytestWarning
.. autoclass:: pytest.PytestDeprecationWarning
.. autoclass:: pytest.RemovedInPytest4Warning
.. autoclass:: pytest.PytestExperimentalApiWarning

View File

@@ -386,11 +386,51 @@ return a result object, with which we can assert the tests' outcomes.
result.assert_outcomes(passed=4)
additionally it is possible to copy examples for a example folder before running pytest on it
.. code:: ini
# content of pytest.ini
[pytest]
pytester_example_dir = .
.. code:: python
# content of test_example.py
def test_plugin(testdir):
testdir.copy_example("test_example.py")
testdir.runpytest("-k", "test_example")
def test_example():
pass
.. code::
$ pytest
=========================== test session starts ============================
platform linux -- Python 3.x.y, pytest-3.x.y, py-1.x.y, pluggy-0.x.y
rootdir: $REGENDOC_TMPDIR, inifile: pytest.ini
collected 2 items
test_example.py .. [100%]
============================= warnings summary =============================
$REGENDOC_TMPDIR/test_example.py:4: PytestExperimentalApiWarning: testdir.copy_example is an experimental api that may change over time
testdir.copy_example("test_example.py")
-- Docs: https://docs.pytest.org/en/latest/warnings.html
=================== 2 passed, 1 warnings in 0.12 seconds ===================
For more information about the result object that ``runpytest()`` returns, and
the methods that it provides please check out the :py:class:`RunResult
<_pytest.pytester.RunResult>` documentation.
.. _`writinghooks`:
Writing hook functions

View File

@@ -1,8 +0,0 @@
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:\Python36\python -m tox

View File

@@ -0,0 +1,10 @@
REM scripts called by AppVeyor to setup the environment variables to enable coverage
if not defined PYTEST_NO_COVERAGE (
set "COVERAGE_FILE=%CD%\.coverage"
set "COVERAGE_PROCESS_START=%CD%\.coveragerc"
set "_PYTEST_TOX_COVERAGE_RUN=coverage run -m"
set "_PYTEST_TOX_EXTRA_DEP=coverage-enable-subprocess"
echo Coverage setup completed
) else (
echo Skipping coverage setup, PYTEST_NO_COVERAGE is set
)

View File

@@ -9,11 +9,11 @@ against itself, passing on many different interpreters and platforms.
This release contains a number of bugs fixes and improvements, so users are encouraged
to take a look at the CHANGELOG:
http://doc.pytest.org/en/latest/changelog.html
https://docs.pytest.org/en/latest/changelog.html
For complete documentation, please visit:
http://docs.pytest.org
https://docs.pytest.org/en/latest/
As usual, you can upgrade from pypi via:

View File

@@ -7,7 +7,7 @@ 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.
The full changelog is available at https://docs.pytest.org/en/latest/changelog.html.
Thanks to all who contributed to this release, among them:

View File

@@ -0,0 +1,11 @@
REM script called by AppVeyor to combine and upload coverage information to codecov
if not defined PYTEST_NO_COVERAGE (
echo Prepare to upload coverage information
C:\Python36\Scripts\pip install codecov
C:\Python36\Scripts\coverage combine
C:\Python36\Scripts\coverage xml --ignore-errors
C:\Python36\Scripts\coverage report -m --ignore-errors
C:\Python36\Scripts\codecov --required -X gcov pycov search -f coverage.xml --flags %TOXENV:-= % windows
) else (
echo Skipping coverage upload, PYTEST_NO_COVERAGE is set
)

View File

@@ -59,7 +59,7 @@ def get_environment_marker_support_level():
def main():
extras_require = {}
install_requires = [
"py>=1.5.0",
"py>=1.5.0", # if py gets upgrade to >=1.6, remove _width_of_current_line in terminal.py
"six>=1.10.0",
"setuptools",
"attrs>=17.4.0",
@@ -69,26 +69,30 @@ def main():
# if _PYTEST_SETUP_SKIP_PLUGGY_DEP is set, skip installing pluggy;
# used by tox.ini to test with pluggy master
if "_PYTEST_SETUP_SKIP_PLUGGY_DEP" not in os.environ:
install_requires.append("pluggy>=0.5,<0.8")
install_requires.append("pluggy>=0.7")
environment_marker_support_level = get_environment_marker_support_level()
if environment_marker_support_level >= 2:
install_requires.append('funcsigs;python_version<"3.0"')
install_requires.append('pathlib2>=2.2.0;python_version<"3.6"')
install_requires.append('colorama;sys_platform=="win32"')
elif environment_marker_support_level == 1:
extras_require[':python_version<"3.0"'] = ["funcsigs"]
extras_require[':python_version<"3.6"'] = ["pathlib2>=2.2.0"]
extras_require[':sys_platform=="win32"'] = ["colorama"]
else:
if sys.platform == "win32":
install_requires.append("colorama")
if sys.version_info < (3, 0):
install_requires.append("funcsigs")
if sys.version_info < (3, 6):
install_requires.append("pathlib2>=2.2.0")
setup(
name="pytest",
description="pytest: simple powerful testing with Python",
long_description=long_description,
use_scm_version={"write_to": "src/_pytest/_version.py"},
url="http://pytest.org",
url="https://docs.pytest.org/en/latest/",
project_urls={
"Source": "https://github.com/pytest-dev/pytest",
"Tracker": "https://github.com/pytest-dev/pytest/issues",

View File

@@ -2,7 +2,7 @@
# CHANGES:
# - some_str is replaced, trying to create unicode strings
#
from __future__ import absolute_import, division, print_function
from __future__ import absolute_import, division, print_function, unicode_literals
import types
from six import text_type
@@ -51,17 +51,17 @@ def format_exception_only(etype, value):
pass
else:
filename = filename or "<string>"
lines.append(' File "%s", line %d\n' % (filename, lineno))
lines.append(' File "{}", line {}\n'.format(filename, lineno))
if badline is not None:
if isinstance(badline, bytes): # python 2 only
badline = badline.decode("utf-8", "replace")
lines.append(u" %s\n" % badline.strip())
lines.append(" {}\n".format(badline.strip()))
if offset is not None:
caretspace = badline.rstrip("\n")[:offset].lstrip()
# non-space whitespace (likes tabs) must be kept for alignment
caretspace = ((c.isspace() and c or " ") for c in caretspace)
# only three spaces to account for offset1 == pos 0
lines.append(" %s^\n" % "".join(caretspace))
lines.append(" {}^\n".format("".join(caretspace)))
value = msg
lines.append(_format_final_exc_line(stype, value))
@@ -72,9 +72,9 @@ def _format_final_exc_line(etype, value):
"""Return a list of a single line -- normal case for format_exception_only"""
valuestr = _some_str(value)
if value is None or not valuestr:
line = "%s\n" % etype
line = "{}\n".format(etype)
else:
line = "%s: %s\n" % (etype, valuestr)
line = "{}: {}\n".format(etype, valuestr)
return line
@@ -83,7 +83,7 @@ def _some_str(value):
return text_type(value)
except Exception:
try:
return str(value)
return bytes(value).decode("UTF-8", "replace")
except Exception:
pass
return "<unprintable %s object>" % type(value).__name__
return "<unprintable {} object>".format(type(value).__name__)

View File

@@ -1,5 +1,6 @@
from __future__ import absolute_import, division, print_function
import inspect
import pprint
import sys
import traceback
from inspect import CO_VARARGS, CO_VARKEYWORDS
@@ -10,6 +11,7 @@ from weakref import ref
from _pytest.compat import _PY2, _PY3, PY35, safe_str
from six import text_type
import py
import six
builtin_repr = repr
@@ -127,7 +129,7 @@ class Frame(object):
"""
f_locals = self.f_locals.copy()
f_locals.update(vars)
py.builtin.exec_(code, self.f_globals, f_locals)
six.exec_(code, self.f_globals, f_locals)
def repr(self, object):
""" return a 'safe' (non-recursive, one-line) string repr for 'object'
@@ -448,6 +450,7 @@ class ExceptionInfo(object):
abspath=False,
tbfilter=True,
funcargs=False,
truncate_locals=True,
):
""" return str()able representation of this exception info.
showlocals: show locals per traceback entry
@@ -472,6 +475,7 @@ class ExceptionInfo(object):
abspath=abspath,
tbfilter=tbfilter,
funcargs=funcargs,
truncate_locals=truncate_locals,
)
return fmt.repr_excinfo(self)
@@ -511,6 +515,7 @@ class FormattedExcinfo(object):
abspath = attr.ib(default=True)
tbfilter = attr.ib(default=True)
funcargs = attr.ib(default=False)
truncate_locals = attr.ib(default=True)
astcache = attr.ib(default=attr.Factory(dict), init=False, repr=False)
def _getindent(self, source):
@@ -593,7 +598,10 @@ class FormattedExcinfo(object):
# This formatting could all be handled by the
# _repr() function, which is only reprlib.Repr in
# disguise, so is very configurable.
str_repr = self._saferepr(value)
if self.truncate_locals:
str_repr = self._saferepr(value)
else:
str_repr = pprint.pformat(value)
# if len(str_repr) < 70 or not isinstance(value,
# (list, tuple, dict)):
lines.append("%-10s = %s" % (name, str_repr))
@@ -712,7 +720,9 @@ class FormattedExcinfo(object):
repr_chain = []
e = excinfo.value
descr = None
while e is not None:
seen = set()
while e is not None and id(e) not in seen:
seen.add(id(e))
if excinfo:
reprtraceback = self.repr_traceback(excinfo)
reprcrash = excinfo._getreprcrash()

View File

@@ -8,6 +8,7 @@ import marshal
import os
import re
import six
import string
import struct
import sys
import types
@@ -16,7 +17,8 @@ import atomicwrites
import py
from _pytest.assertion import util
from _pytest.compat import PurePath, spec_from_file_location
from _pytest.paths import fnmatch_ex
# pytest caches rewritten pycs in __pycache__.
if hasattr(imp, "get_tag"):
@@ -45,14 +47,6 @@ else:
return ast.Call(a, b, c, None, None)
if sys.version_info >= (3, 4):
from importlib.util import spec_from_file_location
else:
def spec_from_file_location(*_, **__):
return None
class AssertionRewritingHook(object):
"""PEP302 Import hook which rewrites asserts."""
@@ -64,12 +58,27 @@ class AssertionRewritingHook(object):
self._rewritten_names = set()
self._register_with_pkg_resources()
self._must_rewrite = set()
# flag to guard against trying to rewrite a pyc file while we are already writing another pyc file,
# which might result in infinite recursion (#3506)
self._writing_pyc = False
self._basenames_to_check_rewrite = {"conftest"}
self._marked_for_rewrite_cache = {}
self._session_paths_checked = False
def set_session(self, session):
self.session = session
self._session_paths_checked = False
def _imp_find_module(self, name, path=None):
"""Indirection so we can mock calls to find_module originated from the hook during testing"""
return imp.find_module(name, path)
def find_module(self, name, path=None):
if self._writing_pyc:
return None
state = self.config._assertstate
if self._early_rewrite_bailout(name, state):
return None
state.trace("find_module called for: %s" % name)
names = name.rsplit(".", 1)
lastname = names[-1]
@@ -82,7 +91,7 @@ class AssertionRewritingHook(object):
pth = path[0]
if pth is None:
try:
fd, fn, desc = imp.find_module(lastname, path)
fd, fn, desc = self._imp_find_module(lastname, path)
except ImportError:
return None
if fd is not None:
@@ -151,12 +160,54 @@ class AssertionRewritingHook(object):
# Probably a SyntaxError in the test.
return None
if write:
_write_pyc(state, co, source_stat, pyc)
self._writing_pyc = True
try:
_write_pyc(state, co, source_stat, pyc)
finally:
self._writing_pyc = False
else:
state.trace("found cached rewritten pyc for %r" % (fn,))
self.modules[name] = co, pyc
return self
def _early_rewrite_bailout(self, name, state):
"""
This is a fast way to get out of rewriting modules. Profiling has
shown that the call to imp.find_module (inside of the find_module
from this class) is a major slowdown, so, this method tries to
filter what we're sure won't be rewritten before getting to it.
"""
if self.session is not None and not self._session_paths_checked:
self._session_paths_checked = True
for path in self.session._initialpaths:
# Make something as c:/projects/my_project/path.py ->
# ['c:', 'projects', 'my_project', 'path.py']
parts = str(path).split(os.path.sep)
# add 'path' to basenames to be checked.
self._basenames_to_check_rewrite.add(os.path.splitext(parts[-1])[0])
# Note: conftest already by default in _basenames_to_check_rewrite.
parts = name.split(".")
if parts[-1] in self._basenames_to_check_rewrite:
return False
# For matching the name it must be as if it was a filename.
path = PurePath(os.path.sep.join(parts) + ".py")
for pat in self.fnpats:
# if the pattern contains subdirectories ("tests/**.py" for example) we can't bail out based
# on the name alone because we need to match against the full path
if os.path.dirname(pat):
return False
if fnmatch_ex(pat, path):
return False
if self._is_marked_for_rewrite(name, state):
return False
state.trace("early skip of rewriting module: %s" % (name,))
return True
def _should_rewrite(self, name, fn_pypath, state):
# always rewrite conftest files
fn = str(fn_pypath)
@@ -176,12 +227,20 @@ class AssertionRewritingHook(object):
state.trace("matched test file %r" % (fn,))
return True
for marked in self._must_rewrite:
if name == marked or name.startswith(marked + "."):
state.trace("matched marked file %r (from %r)" % (name, marked))
return True
return self._is_marked_for_rewrite(name, state)
return False
def _is_marked_for_rewrite(self, name, state):
try:
return self._marked_for_rewrite_cache[name]
except KeyError:
for marked in self._must_rewrite:
if name == marked or name.startswith(marked + "."):
state.trace("matched marked file %r (from %r)" % (name, marked))
self._marked_for_rewrite_cache[name] = True
return True
self._marked_for_rewrite_cache[name] = False
return False
def mark_rewrite(self, *names):
"""Mark import names as needing to be rewritten.
@@ -198,24 +257,29 @@ class AssertionRewritingHook(object):
):
self._warn_already_imported(name)
self._must_rewrite.update(names)
self._marked_for_rewrite_cache.clear()
def _warn_already_imported(self, name):
self.config.warn(
"P1", "Module already imported so cannot be rewritten: %s" % name
from _pytest.warning_types import PytestWarning
from _pytest.warnings import _issue_config_warning
_issue_config_warning(
PytestWarning("Module already imported so cannot be rewritten: %s" % name),
self.config,
)
def load_module(self, name):
# If there is an existing module object named 'fullname' in
# sys.modules, the loader must use that existing module. (Otherwise,
# the reload() builtin will not work correctly.)
if name in sys.modules:
return sys.modules[name]
co, pyc = self.modules.pop(name)
# I wish I could just call imp.load_compiled here, but __file__ has to
# be set properly. In Python 3.2+, this all would be handled correctly
# by load_compiled.
mod = sys.modules[name] = imp.new_module(name)
if name in sys.modules:
# If there is an existing module object named 'fullname' in
# sys.modules, the loader must use that existing module. (Otherwise,
# the reload() builtin will not work correctly.)
mod = sys.modules[name]
else:
# I wish I could just call imp.load_compiled here, but __file__ has to
# be set properly. In Python 3.2+, this all would be handled correctly
# by load_compiled.
mod = sys.modules[name] = imp.new_module(name)
try:
mod.__file__ = co.co_filename
# Normally, this attribute is 3.2+.
@@ -223,7 +287,7 @@ class AssertionRewritingHook(object):
mod.__loader__ = self
# Normally, this attribute is 3.4+
mod.__spec__ = spec_from_file_location(name, co.co_filename, loader=self)
py.builtin.exec_(co, mod.__dict__)
six.exec_(co, mod.__dict__)
except: # noqa
if name in sys.modules:
del sys.modules[name]
@@ -232,7 +296,7 @@ class AssertionRewritingHook(object):
def is_package(self, name):
try:
fd, fn, desc = imp.find_module(name)
fd, fn, desc = self._imp_find_module(name)
except ImportError:
return False
if fd is not None:
@@ -402,12 +466,15 @@ def _saferepr(obj):
JSON reprs.
"""
repr = py.io.saferepr(obj)
if isinstance(repr, six.text_type):
t = six.text_type
else:
t = six.binary_type
return repr.replace(t("\n"), t("\\n"))
r = py.io.saferepr(obj)
# only occurs in python2.x, repr must return text in python3+
if isinstance(r, bytes):
# Represent unprintable bytes as `\x##`
r = u"".join(
u"\\x{:x}".format(ord(c)) if c not in string.printable else c.decode()
for c in r
)
return r.replace(u"\n", u"\\n")
from _pytest.assertion.util import format_explanation as _format_explanation # noqa
@@ -425,20 +492,18 @@ def _format_assertmsg(obj):
# contains a newline it gets escaped, however if an object has a
# .__repr__() which contains newlines it does not get escaped.
# However in either case we want to preserve the newline.
if isinstance(obj, six.text_type) or isinstance(obj, six.binary_type):
s = obj
is_repr = False
else:
s = py.io.saferepr(obj)
is_repr = True
if isinstance(s, six.text_type):
t = six.text_type
else:
t = six.binary_type
s = s.replace(t("\n"), t("\n~")).replace(t("%"), t("%%"))
if is_repr:
s = s.replace(t("\\n"), t("\n~"))
return s
replaces = [(u"\n", u"\n~"), (u"%", u"%%")]
if not isinstance(obj, six.string_types):
obj = py.io.saferepr(obj)
replaces.append((u"\\n", u"\n~"))
if isinstance(obj, bytes):
replaces = [(r1.encode(), r2.encode()) for r1, r2 in replaces]
for r1, r2 in replaces:
obj = obj.replace(r1, r2)
return obj
def _should_repr_global_name(obj):
@@ -448,10 +513,9 @@ def _should_repr_global_name(obj):
def _format_boolop(explanations, is_or):
explanation = "(" + (is_or and " or " or " and ").join(explanations) + ")"
if isinstance(explanation, six.text_type):
t = six.text_type
return explanation.replace(u"%", u"%%")
else:
t = six.binary_type
return explanation.replace(t("%"), t("%%"))
return explanation.replace(b"%", b"%%")
def _call_reprcompare(ops, results, expls, each_obj):
@@ -741,13 +805,17 @@ class AssertionRewriter(ast.NodeVisitor):
the expression is false.
"""
if isinstance(assert_.test, ast.Tuple) and self.config is not None:
fslocation = (self.module_path, assert_.lineno)
self.config.warn(
"R1",
"assertion is always true, perhaps " "remove parentheses?",
fslocation=fslocation,
if isinstance(assert_.test, ast.Tuple) and len(assert_.test.elts) >= 1:
from _pytest.warning_types import PytestWarning
import warnings
warnings.warn_explicit(
PytestWarning("assertion is always true, perhaps remove parentheses?"),
category=None,
filename=str(self.module_path),
lineno=assert_.lineno,
)
self.statements = []
self.variables = []
self.variable_counter = itertools.count()

View File

@@ -187,9 +187,9 @@ def _diff_text(left, right, verbose=False):
r = r.replace(r"\r", "\r")
return r
if isinstance(left, six.binary_type):
if isinstance(left, bytes):
left = escape_for_readable_diff(left)
if isinstance(right, six.binary_type):
if isinstance(right, bytes):
right = escape_for_readable_diff(right)
if not verbose:
i = 0 # just in case left or right has zero length

View File

@@ -5,38 +5,55 @@ the name cache was not chosen to ensure pluggy automatically
ignores the external pytest-cache
"""
from __future__ import absolute_import, division, print_function
from collections import OrderedDict
import py
import six
import attr
import pytest
import json
import os
from os.path import sep as _sep, altsep as _altsep
import shutil
from . import paths
from .compat import _PY2 as PY2, Path
README_CONTENT = u"""\
# pytest cache directory #
This directory contains data from the pytest's cache plugin,
which provides the `--lf` and `--ff` options, as well as the `cache` fixture.
**Do not** commit this to version control.
See [the docs](https://docs.pytest.org/en/latest/cache.html) for more information.
"""
@attr.s
class Cache(object):
def __init__(self, config):
self.config = config
self._cachedir = Cache.cache_dir_from_config(config)
self.trace = config.trace.root.get("cache")
if config.getoption("cacheclear"):
self.trace("clearing cachedir")
if self._cachedir.check():
self._cachedir.remove()
self._cachedir.mkdir()
_cachedir = attr.ib(repr=False)
_config = attr.ib(repr=False)
@classmethod
def for_config(cls, config):
cachedir = cls.cache_dir_from_config(config)
if config.getoption("cacheclear") and cachedir.exists():
shutil.rmtree(str(cachedir))
cachedir.mkdir()
return cls(cachedir, config)
@staticmethod
def cache_dir_from_config(config):
cache_dir = config.getini("cache_dir")
cache_dir = os.path.expanduser(cache_dir)
cache_dir = os.path.expandvars(cache_dir)
if os.path.isabs(cache_dir):
return py.path.local(cache_dir)
else:
return config.rootdir.join(cache_dir)
return paths.resolve_from_str(config.getini("cache_dir"), config.rootdir)
def warn(self, fmt, **args):
from _pytest.warnings import _issue_config_warning
from _pytest.warning_types import PytestWarning
_issue_config_warning(
PytestWarning(fmt.format(**args) if args else fmt), self._config
)
def makedir(self, name):
""" return a directory path object with the given name. If the
@@ -48,12 +65,15 @@ class Cache(object):
Make sure the name contains your plugin or application
identifiers to prevent clashes with other cache users.
"""
if _sep in name or _altsep is not None and _altsep in name:
name = Path(name)
if len(name.parts) > 1:
raise ValueError("name is not allowed to contain path separators")
return self._cachedir.ensure_dir("d", name)
res = self._cachedir.joinpath("d", name)
res.mkdir(exist_ok=True, parents=True)
return py.path.local(res)
def _getvaluepath(self, key):
return self._cachedir.join("v", *key.split("/"))
return self._cachedir.joinpath("v", Path(key))
def get(self, key, default):
""" return cached value for the given key. If no value
@@ -67,13 +87,11 @@ class Cache(object):
"""
path = self._getvaluepath(key)
if path.check():
try:
with path.open("r") as f:
return json.load(f)
except ValueError:
self.trace("cache-invalid at %s" % (path,))
return default
try:
with path.open("r") as f:
return json.load(f)
except (ValueError, IOError, OSError):
return default
def set(self, key, value):
""" save value for the given key.
@@ -86,22 +104,28 @@ class Cache(object):
"""
path = self._getvaluepath(key)
try:
path.dirpath().ensure_dir()
except (py.error.EEXIST, py.error.EACCES):
self.config.warn(
code="I9", message="could not create cache path %s" % (path,)
)
path.parent.mkdir(exist_ok=True, parents=True)
except (IOError, OSError):
self.warn("could not create cache path {path}", path=path)
return
try:
f = path.open("w")
except py.error.ENOTDIR:
self.config.warn(
code="I9", message="cache could not write path %s" % (path,)
)
f = path.open("wb" if PY2 else "w")
except (IOError, OSError):
self.warn("cache could not write path {path}", path=path)
else:
with f:
self.trace("cache-write %s: %r" % (key, value))
json.dump(value, f, indent=2, sort_keys=True)
self._ensure_supporting_files()
def _ensure_supporting_files(self):
"""Create supporting files in the cache dir that are not really part of the cache."""
if self._cachedir.is_dir():
readme_path = self._cachedir / "README.md"
if not readme_path.is_file():
readme_path.write_text(README_CONTENT)
msg = u"# created by pytest automatically, do not change\n*"
self._cachedir.joinpath(".gitignore").write_text(msg, encoding="UTF-8")
class LFPlugin(object):
@@ -116,17 +140,14 @@ class LFPlugin(object):
self._no_failures_behavior = self.config.getoption("last_failed_no_failures")
def pytest_report_collectionfinish(self):
if self.active:
if self.active and self.config.getoption("verbose") >= 0:
if not self._previously_failed_count:
mode = "run {} (no recorded failures)".format(
self._no_failures_behavior
)
else:
noun = "failure" if self._previously_failed_count == 1 else "failures"
suffix = " first" if self.config.getoption("failedfirst") else ""
mode = "rerun previous {count} {noun}{suffix}".format(
count=self._previously_failed_count, suffix=suffix, noun=noun
)
return None
noun = "failure" if self._previously_failed_count == 1 else "failures"
suffix = " first" if self.config.getoption("failedfirst") else ""
mode = "rerun previous {count} {noun}{suffix}".format(
count=self._previously_failed_count, suffix=suffix, noun=noun
)
return "run-last-failure: %s" % mode
def pytest_runtest_logreport(self, report):
@@ -273,7 +294,7 @@ def pytest_cmdline_main(config):
@pytest.hookimpl(tryfirst=True)
def pytest_configure(config):
config.cache = Cache(config)
config.cache = Cache.for_config(config)
config.pluginmanager.register(LFPlugin(config), "lfplugin")
config.pluginmanager.register(NFPlugin(config), "nfplugin")
@@ -296,41 +317,47 @@ def cache(request):
def pytest_report_header(config):
if config.option.verbose:
relpath = py.path.local().bestrelpath(config.cache._cachedir)
return "cachedir: %s" % relpath
cachedir = config.cache._cachedir
# TODO: evaluate generating upward relative paths
# starting with .., ../.. if sensible
try:
displaypath = cachedir.relative_to(config.rootdir)
except ValueError:
displaypath = cachedir
return "cachedir: {}".format(displaypath)
def cacheshow(config, session):
from pprint import pprint
from pprint import pformat
tw = py.io.TerminalWriter()
tw.line("cachedir: " + str(config.cache._cachedir))
if not config.cache._cachedir.check():
if not config.cache._cachedir.is_dir():
tw.line("cache is empty")
return 0
dummy = object()
basedir = config.cache._cachedir
vdir = basedir.join("v")
vdir = basedir / "v"
tw.sep("-", "cache values")
for valpath in sorted(vdir.visit(lambda x: x.isfile())):
key = valpath.relto(vdir).replace(valpath.sep, "/")
for valpath in sorted(x for x in vdir.rglob("*") if x.is_file()):
key = valpath.relative_to(vdir)
val = config.cache.get(key, dummy)
if val is dummy:
tw.line("%s contains unreadable content, " "will be ignored" % key)
else:
tw.line("%s contains:" % key)
stream = py.io.TextIO()
pprint(val, stream=stream)
for line in stream.getvalue().splitlines():
for line in pformat(val).splitlines():
tw.line(" " + line)
ddir = basedir.join("d")
if ddir.isdir() and ddir.listdir():
ddir = basedir / "d"
if ddir.is_dir():
contents = sorted(ddir.rglob("*"))
tw.sep("-", "cache directories")
for p in sorted(basedir.join("d").visit()):
for p in contents:
# if p.check(dir=1):
# print("%s/" % p.relto(basedir))
if p.isfile():
key = p.relto(basedir)
tw.line("%s is a file of length %d" % (key, p.size()))
if p.is_file():
key = p.relative_to(basedir)
tw.line("{} is a file of length {:d}".format(key, p.stat().st_size))
return 0

View File

@@ -16,7 +16,6 @@ import six
import pytest
from _pytest.compat import CaptureIO
patchsysdict = {0: "stdin", 1: "stdout", 2: "stderr"}
@@ -63,8 +62,9 @@ def pytest_load_initial_conftests(early_config, parser, args):
# finally trigger conftest loading but while capturing (issue93)
capman.start_global_capturing()
outcome = yield
out, err = capman.suspend_global_capture()
capman.suspend_global_capture()
if outcome.excinfo is not None:
out, err = capman.read_global_capture()
sys.stdout.write(out)
sys.stderr.write(err)
@@ -85,6 +85,7 @@ class CaptureManager(object):
def __init__(self, method):
self._method = method
self._global_capturing = None
self._current_item = None
def _getcapture(self, method):
if method == "fd":
@@ -96,6 +97,8 @@ class CaptureManager(object):
else:
raise ValueError("unknown capturing method: %r" % method)
# Global capturing control
def start_global_capturing(self):
assert self._global_capturing is None
self._global_capturing = self._getcapture(self._method)
@@ -110,16 +113,15 @@ class CaptureManager(object):
def resume_global_capture(self):
self._global_capturing.resume_capturing()
def suspend_global_capture(self, item=None, in_=False):
if item is not None:
self.deactivate_fixture(item)
def suspend_global_capture(self, in_=False):
cap = getattr(self, "_global_capturing", None)
if cap is not None:
try:
outerr = cap.readouterr()
finally:
cap.suspend_capturing(in_=in_)
return outerr
cap.suspend_capturing(in_=in_)
def read_global_capture(self):
return self._global_capturing.readouterr()
# Fixture Control (its just forwarding, think about removing this later)
def activate_fixture(self, item):
"""If the current item is using ``capsys`` or ``capfd``, activate them so they take precedence over
@@ -135,12 +137,53 @@ class CaptureManager(object):
if fixture is not None:
fixture.close()
def suspend_fixture(self, item):
fixture = getattr(item, "_capture_fixture", None)
if fixture is not None:
fixture._suspend()
def resume_fixture(self, item):
fixture = getattr(item, "_capture_fixture", None)
if fixture is not None:
fixture._resume()
# Helper context managers
@contextlib.contextmanager
def global_and_fixture_disabled(self):
"""Context manager to temporarily disables global and current fixture capturing."""
# Need to undo local capsys-et-al if exists before disabling global capture
self.suspend_fixture(self._current_item)
self.suspend_global_capture(in_=False)
try:
yield
finally:
self.resume_global_capture()
self.resume_fixture(self._current_item)
@contextlib.contextmanager
def item_capture(self, when, item):
self.resume_global_capture()
self.activate_fixture(item)
try:
yield
finally:
self.deactivate_fixture(item)
self.suspend_global_capture(in_=False)
out, err = self.read_global_capture()
item.add_report_section(when, "stdout", out)
item.add_report_section(when, "stderr", err)
# Hooks
@pytest.hookimpl(hookwrapper=True)
def pytest_make_collect_report(self, collector):
if isinstance(collector, pytest.File):
self.resume_global_capture()
outcome = yield
out, err = self.suspend_global_capture()
self.suspend_global_capture()
out, err = self.read_global_capture()
rep = outcome.get_result()
if out:
rep.sections.append(("Captured stdout", out))
@@ -150,29 +193,25 @@ class CaptureManager(object):
yield
@pytest.hookimpl(hookwrapper=True)
def pytest_runtest_setup(self, item):
self.resume_global_capture()
# no need to activate a capture fixture because they activate themselves during creation; this
# only makes sense when a fixture uses a capture fixture, otherwise the capture fixture will
# be activated during pytest_runtest_call
def pytest_runtest_protocol(self, item):
self._current_item = item
yield
self.suspend_capture_item(item, "setup")
self._current_item = None
@pytest.hookimpl(hookwrapper=True)
def pytest_runtest_setup(self, item):
with self.item_capture("setup", item):
yield
@pytest.hookimpl(hookwrapper=True)
def pytest_runtest_call(self, item):
self.resume_global_capture()
# it is important to activate this fixture during the call phase so it overwrites the "global"
# capture
self.activate_fixture(item)
yield
self.suspend_capture_item(item, "call")
with self.item_capture("call", item):
yield
@pytest.hookimpl(hookwrapper=True)
def pytest_runtest_teardown(self, item):
self.resume_global_capture()
self.activate_fixture(item)
yield
self.suspend_capture_item(item, "teardown")
with self.item_capture("teardown", item):
yield
@pytest.hookimpl(tryfirst=True)
def pytest_keyboard_interrupt(self, excinfo):
@@ -182,11 +221,6 @@ class CaptureManager(object):
def pytest_internalerror(self, excinfo):
self.stop_global_capturing()
def suspend_capture_item(self, item, when, in_=False):
out, err = self.suspend_global_capture(item, in_=in_)
item.add_report_section(when, "stdout", out)
item.add_report_section(when, "stderr", err)
capture_fixtures = {"capfd", "capfdbinary", "capsys", "capsysbinary"}
@@ -290,40 +324,54 @@ class CaptureFixture(object):
def __init__(self, captureclass, request):
self.captureclass = captureclass
self.request = request
self._capture = None
self._captured_out = self.captureclass.EMPTY_BUFFER
self._captured_err = self.captureclass.EMPTY_BUFFER
def _start(self):
self._capture = MultiCapture(
out=True, err=True, in_=False, Capture=self.captureclass
)
self._capture.start_capturing()
# Start if not started yet
if getattr(self, "_capture", None) is None:
self._capture = MultiCapture(
out=True, err=True, in_=False, Capture=self.captureclass
)
self._capture.start_capturing()
def close(self):
cap = self.__dict__.pop("_capture", None)
if cap is not None:
self._outerr = cap.pop_outerr_to_orig()
cap.stop_capturing()
if self._capture is not None:
out, err = self._capture.pop_outerr_to_orig()
self._captured_out += out
self._captured_err += err
self._capture.stop_capturing()
self._capture = None
def readouterr(self):
"""Read and return the captured output so far, resetting the internal buffer.
:return: captured content as a namedtuple with ``out`` and ``err`` string attributes
"""
try:
return self._capture.readouterr()
except AttributeError:
return self._outerr
captured_out, captured_err = self._captured_out, self._captured_err
if self._capture is not None:
out, err = self._capture.readouterr()
captured_out += out
captured_err += err
self._captured_out = self.captureclass.EMPTY_BUFFER
self._captured_err = self.captureclass.EMPTY_BUFFER
return CaptureResult(captured_out, captured_err)
def _suspend(self):
"""Suspends this fixture's own capturing temporarily."""
self._capture.suspend_capturing()
def _resume(self):
"""Resumes this fixture's own capturing temporarily."""
self._capture.resume_capturing()
@contextlib.contextmanager
def disabled(self):
"""Temporarily disables capture while inside the 'with' block."""
self._capture.suspend_capturing()
capmanager = self.request.config.pluginmanager.getplugin("capturemanager")
capmanager.suspend_global_capture(item=None, in_=False)
try:
with capmanager.global_and_fixture_disabled():
yield
finally:
capmanager.resume_global_capture()
self._capture.resume_capturing()
def safe_text_dupfile(f, mode, default_encoding="UTF8"):
@@ -440,6 +488,7 @@ class MultiCapture(object):
class NoCapture(object):
EMPTY_BUFFER = None
__init__ = start = done = suspend = resume = lambda *args: None
@@ -449,6 +498,8 @@ class FDCaptureBinary(object):
snap() produces `bytes`
"""
EMPTY_BUFFER = bytes()
def __init__(self, targetfd, tmpfile=None):
self.targetfd = targetfd
try:
@@ -522,6 +573,8 @@ class FDCapture(FDCaptureBinary):
snap() produces text
"""
EMPTY_BUFFER = str()
def snap(self):
res = FDCaptureBinary.snap(self)
enc = getattr(self.tmpfile, "encoding", None)
@@ -531,6 +584,9 @@ class FDCapture(FDCaptureBinary):
class SysCapture(object):
EMPTY_BUFFER = str()
def __init__(self, fd, tmpfile=None):
name = patchsysdict[fd]
self._old = getattr(sys, name)
@@ -568,6 +624,8 @@ class SysCapture(object):
class SysCaptureBinary(SysCapture):
EMPTY_BUFFER = bytes()
def snap(self):
res = self.tmpfile.buffer.getvalue()
self.tmpfile.seek(0)

View File

@@ -8,6 +8,7 @@ import functools
import inspect
import re
import sys
from contextlib import contextmanager
import py
@@ -22,6 +23,7 @@ except ImportError: # pragma: no cover
# Only available in Python 3.4+ or as a backport
enum = None
__all__ = ["Path", "PurePath"]
_PY3 = sys.version_info > (3, 0)
_PY2 = not _PY3
@@ -32,7 +34,6 @@ if _PY3:
else:
from funcsigs import signature, Parameter as Parameter
NoneType = type(None)
NOTSET = object()
@@ -40,6 +41,12 @@ PY35 = sys.version_info[:2] >= (3, 5)
PY36 = sys.version_info[:2] >= (3, 6)
MODULE_NOT_FOUND_ERROR = "ModuleNotFoundError" if PY36 else "ImportError"
if PY36:
from pathlib import Path, PurePath
else:
from pathlib2 import Path, PurePath
if _PY3:
from collections.abc import MutableMapping as MappingMixin
from collections.abc import Mapping, Sequence
@@ -49,6 +56,14 @@ else:
from collections import Mapping, Sequence # noqa
if sys.version_info >= (3, 4):
from importlib.util import spec_from_file_location
else:
def spec_from_file_location(*_, **__):
return None
def _format_args(func):
return str(signature(func))
@@ -78,6 +93,7 @@ def iscoroutinefunction(func):
def getlocation(function, curdir):
function = get_real_func(function)
fn = py.path.local(inspect.getfile(function))
lineno = function.__code__.co_firstlineno
if fn.relto(curdir):
@@ -144,6 +160,13 @@ def getfuncargnames(function, is_method=False, cls=None):
return arg_names
@contextmanager
def dummy_context_manager():
"""Context manager that does nothing, useful in situations where you might need an actual context manager or not
depending on some condition. Using this allow to keep the same code"""
yield
def get_default_arg_names(function):
# Note: this code intentionally mirrors the code at the beginning of getfuncargnames,
# to get the arguments which were excluded from its result because they had default values
@@ -221,12 +244,31 @@ else:
return val.encode("unicode-escape")
class _PytestWrapper(object):
"""Dummy wrapper around a function object for internal use only.
Used to correctly unwrap the underlying function object
when we are creating fixtures, because we wrap the function object ourselves with a decorator
to issue warnings when the fixture function is called directly.
"""
def __init__(self, obj):
self.obj = obj
def get_real_func(obj):
""" gets the real function object of the (possibly) wrapped object by
functools.wraps or functools.partial.
"""
start_obj = obj
for i in range(100):
# __pytest_wrapped__ is set by @pytest.fixture when wrapping the fixture function
# to trigger a warning if it gets called directly instead of by pytest: we don't
# want to unwrap further than this otherwise we lose useful wrappings like @mock.patch (#3774)
new_obj = getattr(obj, "__pytest_wrapped__", None)
if isinstance(new_obj, _PytestWrapper):
obj = new_obj.obj
break
new_obj = getattr(obj, "__wrapped__", None)
if new_obj is None:
break
@@ -242,6 +284,21 @@ def get_real_func(obj):
return obj
def get_real_method(obj, holder):
"""
Attempts to obtain the real function object that might be wrapping ``obj``, while at the same time
returning a bound method to ``holder`` if the original object was a bound method.
"""
try:
is_method = hasattr(obj, "__func__")
obj = get_real_func(obj)
except Exception:
return obj
if is_method and hasattr(obj, "__get__") and callable(obj.__get__):
obj = obj.__get__(holder)
return obj
def getfslineno(obj):
# xxx let decorators etc specify a sane ordering
obj = get_real_func(obj)

View File

@@ -1,6 +1,7 @@
""" command line options, ini-file and conftest.py processing. """
from __future__ import absolute_import, division, print_function
import argparse
import inspect
import shlex
import traceback
import types
@@ -50,6 +51,8 @@ def main(args=None, plugins=None):
:arg plugins: list of plugin objects to be auto-registered during
initialization.
"""
from _pytest.main import EXIT_USAGEERROR
try:
try:
config = _prepareconfig(args, plugins)
@@ -68,7 +71,7 @@ def main(args=None, plugins=None):
tw = py.io.TerminalWriter(sys.stderr)
for msg in e.args:
tw.line("ERROR: {}\n".format(msg), red=True)
return 4
return EXIT_USAGEERROR
class cmdline(object): # compatibility namespace
@@ -175,7 +178,9 @@ def _prepareconfig(args=None, plugins=None):
else:
pluginmanager.register(plugin)
if warning:
config.warn("C1", warning)
from _pytest.warnings import _issue_config_warning
_issue_config_warning(warning, config=config)
return pluginmanager.hook.pytest_cmdline_parse(
pluginmanager=pluginmanager, args=args
)
@@ -252,6 +257,10 @@ class PytestPluginManager(PluginManager):
method = getattr(plugin, name)
opts = super(PytestPluginManager, self).parse_hookimpl_opts(plugin, name)
# consider only actual functions for hooks (#3775)
if not inspect.isroutine(method):
return
# collect unmarked hooks as long as they have the `pytest_' prefix
if opts is None and name.startswith("pytest_"):
opts = {}
@@ -342,6 +351,7 @@ class PytestPluginManager(PluginManager):
else None
)
self._noconftest = namespace.noconftest
self._using_pyargs = namespace.pyargs
testpaths = namespace.file_or_dir
foundanchor = False
for path in testpaths:
@@ -407,12 +417,21 @@ class PytestPluginManager(PluginManager):
_ensure_removed_sysmodule(conftestpath.purebasename)
try:
mod = conftestpath.pyimport()
if hasattr(mod, "pytest_plugins") and self._configured:
if (
hasattr(mod, "pytest_plugins")
and self._configured
and not self._using_pyargs
):
from _pytest.deprecated import (
PYTEST_PLUGINS_FROM_NON_TOP_LEVEL_CONFTEST
)
warnings.warn(PYTEST_PLUGINS_FROM_NON_TOP_LEVEL_CONFTEST)
warnings.warn_explicit(
PYTEST_PLUGINS_FROM_NON_TOP_LEVEL_CONFTEST,
category=None,
filename=str(conftestpath),
lineno=0,
)
except Exception:
raise ConftestImportFailure(conftestpath, sys.exc_info())
@@ -597,7 +616,29 @@ class Config(object):
fin()
def warn(self, code, message, fslocation=None, nodeid=None):
""" generate a warning for this test session. """
"""
.. deprecated:: 3.8
Use :py:func:`warnings.warn` or :py:func:`warnings.warn_explicit` directly instead.
Generate a warning for this test session.
"""
from _pytest.warning_types import RemovedInPytest4Warning
if isinstance(fslocation, (tuple, list)) and len(fslocation) > 2:
filename, lineno = fslocation[:2]
else:
filename = "unknown file"
lineno = 0
msg = "config.warn has been deprecated, use warnings.warn instead"
if nodeid:
msg = "{}: {}".format(nodeid, msg)
warnings.warn_explicit(
RemovedInPytest4Warning(msg),
category=None,
filename=filename,
lineno=lineno,
)
self.hook.pytest_logwarning.call_historic(
kwargs=dict(
code=code, message=message, fslocation=fslocation, nodeid=nodeid
@@ -662,8 +703,8 @@ class Config(object):
r = determine_setup(
ns.inifilename,
ns.file_or_dir + unknown_args,
warnfunc=self.warn,
rootdir_cmd_arg=ns.rootdir or None,
config=self,
)
self.rootdir, self.inifile, self.inicfg = r
self._parser.extra_info["rootdir"] = self.rootdir
@@ -701,6 +742,10 @@ class Config(object):
self.pluginmanager.rewrite_hook = hook
if os.environ.get("PYTEST_DISABLE_PLUGIN_AUTOLOAD"):
# We don't autoload from setuptools entry points, no need to continue.
return
# 'RECORD' available for plugins installed normally (pip install)
# 'SOURCES.txt' available for plugins installed in dev mode (pip install -e)
# for installed plugins 'SOURCES.txt' returns an empty list, and vice-versa
@@ -726,7 +771,10 @@ class Config(object):
self._checkversion()
self._consider_importhook(args)
self.pluginmanager.consider_preparse(args)
self.pluginmanager.load_setuptools_entrypoints("pytest11")
if not os.environ.get("PYTEST_DISABLE_PLUGIN_AUTOLOAD"):
# Don't autoload from setuptools entry point. Only explicitly specified
# plugins are going to be loaded.
self.pluginmanager.load_setuptools_entrypoints("pytest11")
self.pluginmanager.consider_env()
self.known_args_namespace = ns = self._parser.parse_known_args(
args, namespace=copy.copy(self.option)

View File

@@ -2,6 +2,13 @@ import six
import warnings
import argparse
from gettext import gettext as _
import sys as _sys
import py
from ..main import EXIT_USAGEERROR
FILE_OR_DIR = "file_or_dir"
@@ -70,7 +77,8 @@ class Parser(object):
self.optparser = self._getparser()
try_argcomplete(self.optparser)
return self.optparser.parse_args([str(x) for x in args], namespace=namespace)
args = [str(x) if isinstance(x, py.path.local) else x for x in args]
return self.optparser.parse_args(args, namespace=namespace)
def _getparser(self):
from _pytest._argcomplete import filescompleter
@@ -106,7 +114,7 @@ class Parser(object):
the remaining arguments unknown at this point.
"""
optparser = self._getparser()
args = [str(x) for x in args]
args = [str(x) if isinstance(x, py.path.local) else x for x in args]
return optparser.parse_known_args(args, namespace=namespace)
def addini(self, name, help, type=None, default=None):
@@ -174,23 +182,23 @@ class Argument(object):
if isinstance(typ, six.string_types):
if typ == "choice":
warnings.warn(
"type argument to addoption() is a string %r."
" For parsearg this is optional and when supplied"
" should be a type."
"`type` argument to addoption() is the string %r."
" For choices this is optional and can be omitted, "
" but when supplied should be a type (for example `str` or `int`)."
" (options: %s)" % (typ, names),
DeprecationWarning,
stacklevel=3,
stacklevel=4,
)
# argparse expects a type here take it from
# the type of the first element
attrs["type"] = type(attrs["choices"][0])
else:
warnings.warn(
"type argument to addoption() is a string %r."
" For parsearg this should be a type."
"`type` argument to addoption() is the string %r, "
" but when supplied should be a type (for example `str` or `int`)."
" (options: %s)" % (typ, names),
DeprecationWarning,
stacklevel=3,
stacklevel=4,
)
attrs["type"] = Argument._typ_map[typ]
# used in test_parseopt -> test_parse_defaultgetter
@@ -326,6 +334,16 @@ class MyOptionParser(argparse.ArgumentParser):
# an usage error to provide more contextual information to the user
self.extra_info = extra_info
def error(self, message):
"""error(message: string)
Prints a usage message incorporating the message to stderr and
exits.
Overrides the method in parent class to change exit code"""
self.print_usage(_sys.stderr)
args = {"prog": self.prog, "message": message}
self.exit(EXIT_USAGEERROR, _("%(prog)s: error: %(message)s\n") % args)
def parse_args(self, args=None, namespace=None):
"""allow splitting of positional arguments"""
args, argv = self.parse_known_args(args, namespace)

View File

@@ -10,15 +10,12 @@ def exists(path, ignore=EnvironmentError):
return False
def getcfg(args, warnfunc=None):
def getcfg(args, config=None):
"""
Search the list of arguments for a valid ini-file for pytest,
and return a tuple of (rootdir, inifile, cfg-dict).
note: warnfunc is an optional function used to warn
about ini-files that use deprecated features.
This parameter should be removed when pytest
adopts standard deprecation warnings (#1804).
note: config is optional and used only to issue warnings explicitly (#2891).
"""
from _pytest.deprecated import CFG_PYTEST_SECTION
@@ -34,9 +31,15 @@ def getcfg(args, warnfunc=None):
if exists(p):
iniconfig = py.iniconfig.IniConfig(p)
if "pytest" in iniconfig.sections:
if inibasename == "setup.cfg" and warnfunc:
warnfunc(
"C1", CFG_PYTEST_SECTION.format(filename=inibasename)
if inibasename == "setup.cfg" and config is not None:
from _pytest.warnings import _issue_config_warning
from _pytest.warning_types import RemovedInPytest4Warning
_issue_config_warning(
RemovedInPytest4Warning(
CFG_PYTEST_SECTION.format(filename=inibasename)
),
config=config,
)
return base, p, iniconfig["pytest"]
if (
@@ -95,7 +98,7 @@ def get_dirs_from_args(args):
return [get_dir_from_path(path) for path in possible_paths if path.exists()]
def determine_setup(inifile, args, warnfunc=None, rootdir_cmd_arg=None):
def determine_setup(inifile, args, rootdir_cmd_arg=None, config=None):
dirs = get_dirs_from_args(args)
if inifile:
iniconfig = py.iniconfig.IniConfig(inifile)
@@ -105,23 +108,30 @@ def determine_setup(inifile, args, warnfunc=None, rootdir_cmd_arg=None):
for section in sections:
try:
inicfg = iniconfig[section]
if is_cfg_file and section == "pytest" and warnfunc:
if is_cfg_file and section == "pytest" and config is not None:
from _pytest.deprecated import CFG_PYTEST_SECTION
from _pytest.warning_types import RemovedInPytest4Warning
from _pytest.warnings import _issue_config_warning
warnfunc("C1", CFG_PYTEST_SECTION.format(filename=str(inifile)))
_issue_config_warning(
RemovedInPytest4Warning(
CFG_PYTEST_SECTION.format(filename=str(inifile))
),
config,
)
break
except KeyError:
inicfg = None
rootdir = get_common_ancestor(dirs)
else:
ancestor = get_common_ancestor(dirs)
rootdir, inifile, inicfg = getcfg([ancestor], warnfunc=warnfunc)
rootdir, inifile, inicfg = getcfg([ancestor], config=config)
if rootdir is None:
for rootdir in ancestor.parts(reverse=True):
if rootdir.join("setup.py").exists():
break
else:
rootdir, inifile, inicfg = getcfg(dirs, warnfunc=warnfunc)
rootdir, inifile, inicfg = getcfg(dirs, config=config)
if rootdir is None:
rootdir = get_common_ancestor([py.path.local(), ancestor])
is_fs_root = os.path.splitdrive(str(rootdir))[1] == "/"

View File

@@ -5,6 +5,8 @@ import sys
import os
from doctest import UnexpectedException
from _pytest.config import hookimpl
try:
from builtins import breakpoint # noqa
@@ -28,6 +30,12 @@ def pytest_addoption(parser):
help="start a custom interactive Python debugger on errors. "
"For example: --pdbcls=IPython.terminal.debugger:TerminalPdb",
)
group._addoption(
"--trace",
dest="trace",
action="store_true",
help="Immediately break when running each test.",
)
def pytest_configure(config):
@@ -38,6 +46,8 @@ def pytest_configure(config):
else:
pdb_cls = pdb.Pdb
if config.getvalue("trace"):
config.pluginmanager.register(PdbTrace(), "pdbtrace")
if config.getvalue("usepdb"):
config.pluginmanager.register(PdbInvoke(), "pdbinvoke")
@@ -71,7 +81,7 @@ class pytestPDB(object):
_pdb_cls = pdb.Pdb
@classmethod
def set_trace(cls):
def set_trace(cls, set_break=True):
""" invoke PDB set_trace debugging, dropping any IO capturing. """
import _pytest.config
@@ -84,14 +94,16 @@ class pytestPDB(object):
tw.line()
tw.sep(">", "PDB set_trace (IO-capturing turned off)")
cls._pluginmanager.hook.pytest_enter_pdb(config=cls._config)
cls._pdb_cls().set_trace(frame)
if set_break:
cls._pdb_cls().set_trace(frame)
class PdbInvoke(object):
def pytest_exception_interact(self, node, call, report):
capman = node.config.pluginmanager.getplugin("capturemanager")
if capman:
out, err = capman.suspend_global_capture(in_=True)
capman.suspend_global_capture(in_=True)
out, err = capman.read_global_capture()
sys.stdout.write(out)
sys.stdout.write(err)
_enter_pdb(node, call.excinfo, report)
@@ -104,6 +116,30 @@ class PdbInvoke(object):
post_mortem(tb)
class PdbTrace(object):
@hookimpl(hookwrapper=True)
def pytest_pyfunc_call(self, pyfuncitem):
_test_pytest_function(pyfuncitem)
yield
def _test_pytest_function(pyfuncitem):
pytestPDB.set_trace(set_break=False)
testfunction = pyfuncitem.obj
pyfuncitem.obj = pdb.runcall
if pyfuncitem._isyieldedfunction():
arg_list = list(pyfuncitem._args)
arg_list.insert(0, testfunction)
pyfuncitem._args = tuple(arg_list)
else:
if "func" in pyfuncitem._fixtureinfo.argnames:
raise ValueError("--trace can't be used with a fixture named func!")
pyfuncitem.funcargs["func"] = testfunction
new_list = list(pyfuncitem._fixtureinfo.argnames)
new_list.append("func")
pyfuncitem._fixtureinfo.argnames = tuple(new_list)
def _enter_pdb(node, excinfo, rep):
# XXX we re-use the TerminalReporter's terminalwriter
# because this seems to avoid some encoding related troubles

View File

@@ -7,14 +7,16 @@ be removed when the time comes.
"""
from __future__ import absolute_import, division, print_function
from _pytest.warning_types import RemovedInPytest4Warning
class RemovedInPytest4Warning(DeprecationWarning):
"""warning class for features removed in pytest 4.0"""
MAIN_STR_ARGS = RemovedInPytest4Warning(
"passing a string to pytest.main() is deprecated, "
"pass a list of arguments instead."
)
MAIN_STR_ARGS = "passing a string to pytest.main() is deprecated, " "pass a list of arguments instead."
YIELD_TESTS = "yield tests are deprecated, and scheduled to be removed in pytest 4.0"
YIELD_TESTS = RemovedInPytest4Warning(
"yield tests are deprecated, and scheduled to be removed in pytest 4.0"
)
FUNCARG_PREFIX = (
'{name}: declaring fixtures using "pytest_funcarg__" prefix is deprecated '
@@ -22,11 +24,17 @@ FUNCARG_PREFIX = (
"Please remove the prefix and use the @pytest.fixture decorator instead."
)
FIXTURE_FUNCTION_CALL = (
'Fixture "{name}" called directly. Fixtures are not meant to be called directly, '
"are created automatically when test functions request them as parameters. "
"See https://docs.pytest.org/en/latest/fixture.html for more information."
)
CFG_PYTEST_SECTION = (
"[pytest] section in {filename} files is deprecated, use [tool:pytest] instead."
)
GETFUNCARGVALUE = "use of getfuncargvalue is deprecated, use getfixturevalue"
GETFUNCARGVALUE = "getfuncargvalue is deprecated, use getfixturevalue"
RESULT_LOG = (
"--result-log is deprecated and scheduled for removal in pytest 4.0.\n"
@@ -45,7 +53,11 @@ MARK_PARAMETERSET_UNPACKING = RemovedInPytest4Warning(
"For more details, see: https://docs.pytest.org/en/latest/parametrize.html"
)
RECORD_XML_PROPERTY = (
NODE_WARN = RemovedInPytest4Warning(
"Node.warn(code, message) form has been deprecated, use Node.warn(warning_instance) instead."
)
RECORD_XML_PROPERTY = RemovedInPytest4Warning(
'Fixture renamed from "record_xml_property" to "record_property" as user '
"properties are now available to all reporters.\n"
'"record_xml_property" is now deprecated.'
@@ -55,7 +67,7 @@ COLLECTOR_MAKEITEM = RemovedInPytest4Warning(
"pycollector makeitem was removed " "as it is an accidentially leaked internal api"
)
METAFUNC_ADD_CALL = (
METAFUNC_ADD_CALL = RemovedInPytest4Warning(
"Metafunc.addcall is deprecated and scheduled to be removed in pytest 4.0.\n"
"Please use Metafunc.parametrize instead."
)
@@ -65,3 +77,7 @@ PYTEST_PLUGINS_FROM_NON_TOP_LEVEL_CONFTEST = RemovedInPytest4Warning(
"because it affects the entire directory tree in a non-explicit way.\n"
"Please move it to the top level conftest file instead."
)
PYTEST_NAMESPACE = RemovedInPytest4Warning(
"pytest_namespace is deprecated and will be removed soon"
)

View File

@@ -203,7 +203,8 @@ class DoctestItem(pytest.Item):
return
capman = self.config.pluginmanager.getplugin("capturemanager")
if capman:
out, err = capman.suspend_global_capture(in_=True)
capman.suspend_global_capture(in_=True)
out, err = capman.read_global_capture()
sys.stdout.write(out)
sys.stderr.write(err)

View File

@@ -5,6 +5,8 @@ import inspect
import sys
import warnings
from collections import OrderedDict, deque, defaultdict
import six
from more_itertools import flatten
import attr
@@ -27,7 +29,10 @@ from _pytest.compat import (
getfuncargnames,
safe_getattr,
FuncargnamesCompatAttr,
get_real_method,
_PytestWrapper,
)
from _pytest.deprecated import FIXTURE_FUNCTION_CALL, RemovedInPytest4Warning
from _pytest.outcomes import fail, TEST_OUTCOME
FIXTURE_MSG = 'fixtures cannot have "pytest_funcarg__" prefix and be decorated with @pytest.fixture:\n{}'
@@ -45,6 +50,7 @@ def pytest_sessionstart(session):
scopename2class.update(
{
"package": _pytest.python.Package,
"class": _pytest.python.Class,
"module": _pytest.python.Module,
"function": _pytest.nodes.Item,
@@ -58,6 +64,7 @@ scopename2class = {}
scope2props = dict(session=())
scope2props["package"] = ("fspath",)
scope2props["module"] = ("fspath", "module")
scope2props["class"] = scope2props["module"] + ("cls",)
scope2props["instance"] = scope2props["class"] + ("instance",)
@@ -80,6 +87,21 @@ def scopeproperty(name=None, doc=None):
return decoratescope
def get_scope_package(node, fixturedef):
import pytest
cls = pytest.Package
current = node
fixture_package_name = "%s/%s" % (fixturedef.baseid, "__init__.py")
while current and (
type(current) is not cls or fixture_package_name != current.nodeid
):
current = current.parent
if current is None:
return node.session
return current
def get_scope_node(node, scope):
cls = scopename2class.get(scope)
if cls is None:
@@ -173,9 +195,11 @@ def get_parametrized_fixture_keys(item, scopenum):
continue
if scopenum == 0: # session
key = (argname, param_index)
elif scopenum == 1: # module
elif scopenum == 1: # package
key = (argname, param_index, item.fspath.dirpath())
elif scopenum == 2: # module
key = (argname, param_index, item.fspath)
elif scopenum == 2: # class
elif scopenum == 3: # class
key = (argname, param_index, item.fspath, item.cls)
yield key
@@ -274,11 +298,43 @@ def get_direct_param_fixture_func(request):
return request.param
@attr.s(slots=True)
class FuncFixtureInfo(object):
def __init__(self, argnames, names_closure, name2fixturedefs):
self.argnames = argnames
self.names_closure = names_closure
self.name2fixturedefs = name2fixturedefs
# original function argument names
argnames = attr.ib(type=tuple)
# argnames that function immediately requires. These include argnames +
# fixture names specified via usefixtures and via autouse=True in fixture
# definitions.
initialnames = attr.ib(type=tuple)
names_closure = attr.ib() # type: List[str]
name2fixturedefs = attr.ib() # type: List[str, List[FixtureDef]]
def prune_dependency_tree(self):
"""Recompute names_closure from initialnames and name2fixturedefs
Can only reduce names_closure, which means that the new closure will
always be a subset of the old one. The order is preserved.
This method is needed because direct parametrization may shadow some
of the fixtures that were included in the originally built dependency
tree. In this way the dependency tree can get pruned, and the closure
of argnames may get reduced.
"""
closure = set()
working_set = set(self.initialnames)
while working_set:
argname = working_set.pop()
# argname may be smth not included in the original names_closure,
# in which case we ignore it. This currently happens with pseudo
# FixtureDefs which wrap 'get_direct_param_fixture_func(request)'.
# So they introduce the new dependency 'request' which might have
# been missing in the original tree (closure).
if argname not in closure and argname in self.names_closure:
closure.add(argname)
if argname in self.name2fixturedefs:
working_set.update(self.name2fixturedefs[argname][-1].argnames)
self.names_closure[:] = sorted(closure, key=self.names_closure.index)
class FixtureRequest(FuncargnamesCompatAttr):
@@ -580,7 +636,10 @@ class FixtureRequest(FuncargnamesCompatAttr):
if scope == "function":
# this might also be a non-function Item despite its attribute name
return self._pyfuncitem
node = get_scope_node(self._pyfuncitem, scope)
if scope == "package":
node = get_scope_package(self._pyfuncitem, self._fixturedef)
else:
node = get_scope_node(self._pyfuncitem, scope)
if node is None and scope == "class":
# fallback to function item itself
node = self._pyfuncitem
@@ -624,7 +683,7 @@ class ScopeMismatchError(Exception):
"""
scopes = "session module class function".split()
scopes = "session package module class function".split()
scopenum_function = scopes.index("function")
@@ -734,23 +793,26 @@ def call_fixture_func(fixturefunc, request, kwargs):
if yieldctx:
it = fixturefunc(**kwargs)
res = next(it)
def teardown():
try:
next(it)
except StopIteration:
pass
else:
fail_fixturefunc(
fixturefunc, "yield_fixture function has more than one 'yield'"
)
request.addfinalizer(teardown)
finalizer = functools.partial(_teardown_yield_fixture, fixturefunc, it)
request.addfinalizer(finalizer)
else:
res = fixturefunc(**kwargs)
return res
def _teardown_yield_fixture(fixturefunc, it):
"""Executes the teardown of a fixture function by advancing the iterator after the
yield and ensure the iteration ends (if not it means there is more than one yield in the function)"""
try:
next(it)
except StopIteration:
pass
else:
fail_fixturefunc(
fixturefunc, "yield_fixture function has more than one 'yield'"
)
class FixtureDef(object):
""" A container for a factory definition. """
@@ -795,7 +857,7 @@ class FixtureDef(object):
if exceptions:
e = exceptions[0]
del exceptions # ensure we don't keep all frames alive because of the traceback
py.builtin._reraise(*e)
six.reraise(*e)
finally:
hook = self._fixturemanager.session.gethookproxy(request.node.fspath)
@@ -822,7 +884,7 @@ class FixtureDef(object):
result, cache_key, err = cached_result
if my_cache_key == cache_key:
if err is not None:
py.builtin._reraise(*err)
six.reraise(*err)
else:
return result
# we have a previous but differently parametrized fixture instance
@@ -841,15 +903,10 @@ class FixtureDef(object):
)
def pytest_fixture_setup(fixturedef, request):
""" Execution of fixture setup. """
kwargs = {}
for argname in fixturedef.argnames:
fixdef = request._get_active_fixturedef(argname)
result, arg_cache_key, exc = fixdef.cached_result
request._check_scope(argname, request.scope, fixdef.scope)
kwargs[argname] = result
def resolve_fixture_function(fixturedef, request):
"""Gets the actual callable that can be called to obtain the fixture value, dealing with unittest-specific
instances and bound methods.
"""
fixturefunc = fixturedef.func
if fixturedef.unittest:
if request.instance is not None:
@@ -863,6 +920,19 @@ def pytest_fixture_setup(fixturedef, request):
fixturefunc = getimfunc(fixturedef.func)
if fixturefunc != fixturedef.func:
fixturefunc = fixturefunc.__get__(request.instance)
return fixturefunc
def pytest_fixture_setup(fixturedef, request):
""" Execution of fixture setup. """
kwargs = {}
for argname in fixturedef.argnames:
fixdef = request._get_active_fixturedef(argname)
result, arg_cache_key, exc = fixdef.cached_result
request._check_scope(argname, request.scope, fixdef.scope)
kwargs[argname] = result
fixturefunc = resolve_fixture_function(fixturedef, request)
my_cache_key = request.param_index
try:
result = call_fixture_func(fixturefunc, request, kwargs)
@@ -881,6 +951,41 @@ def _ensure_immutable_ids(ids):
return tuple(ids)
def wrap_function_to_warning_if_called_directly(function, fixture_marker):
"""Wrap the given fixture function so we can issue warnings about it being called directly, instead of
used as an argument in a test function.
"""
is_yield_function = is_generator(function)
msg = FIXTURE_FUNCTION_CALL.format(name=fixture_marker.name or function.__name__)
warning = RemovedInPytest4Warning(msg)
if is_yield_function:
@functools.wraps(function)
def result(*args, **kwargs):
__tracebackhide__ = True
warnings.warn(warning, stacklevel=3)
for x in function(*args, **kwargs):
yield x
else:
@functools.wraps(function)
def result(*args, **kwargs):
__tracebackhide__ = True
warnings.warn(warning, stacklevel=3)
return function(*args, **kwargs)
if six.PY2:
result.__wrapped__ = function
# keep reference to the original function in our own custom attribute so we don't unwrap
# further than this point and lose useful wrappings like @mock.patch (#3774)
result.__pytest_wrapped__ = _PytestWrapper(function)
return result
@attr.s(frozen=True)
class FixtureFunctionMarker(object):
scope = attr.ib()
@@ -898,6 +1003,8 @@ class FixtureFunctionMarker(object):
"fixture is being applied more than once to the same function"
)
function = wrap_function_to_warning_if_called_directly(function, self)
function._pytestfixturefunction = self
return function
@@ -905,16 +1012,27 @@ class FixtureFunctionMarker(object):
def fixture(scope="function", params=None, autouse=False, ids=None, name=None):
"""Decorator to mark a fixture factory function.
This decorator can be used (with or without parameters) to define a
fixture function. The name of the fixture function can later be
referenced to cause its invocation ahead of running tests: test
modules or classes can use the pytest.mark.usefixtures(fixturename)
marker. Test functions can directly use fixture names as input
This decorator can be used, with or without parameters, to define a
fixture function.
The name of the fixture function can later be referenced to cause its
invocation ahead of running tests: test
modules or classes can use the ``pytest.mark.usefixtures(fixturename)``
marker.
Test functions can directly use fixture names as input
arguments in which case the fixture instance returned from the fixture
function will be injected.
Fixtures can provide their values to test functions using ``return`` or ``yield``
statements. When using ``yield`` the code block after the ``yield`` statement is executed
as teardown code regardless of the test outcome, and must yield exactly once.
:arg scope: the scope for which this fixture is shared, one of
"function" (default), "class", "module" or "session".
``"function"`` (default), ``"class"``, ``"module"``,
``"package"`` or ``"session"``.
``"package"`` is considered **experimental** at this time.
:arg params: an optional list of parameters which will cause multiple
invocations of the fixture function and all of the tests
@@ -935,10 +1053,6 @@ def fixture(scope="function", params=None, autouse=False, ids=None, name=None):
to resolve this is to name the decorated function
``fixture_<fixturename>`` and then use
``@pytest.fixture(name='<fixturename>')``.
Fixtures can optionally provide their values to test functions using a ``yield`` statement,
instead of ``return``. In this case, the code block after the ``yield`` statement is executed
as teardown code regardless of the test outcome. A fixture function must yield exactly once.
"""
if callable(scope) and params is None and autouse is False:
# direct decoration
@@ -954,13 +1068,7 @@ def yield_fixture(scope="function", params=None, autouse=False, ids=None, name=N
.. deprecated:: 3.0
Use :py:func:`pytest.fixture` directly instead.
"""
if callable(scope) and params is None and not autouse:
# direct decoration
return FixtureFunctionMarker("function", params, autouse, ids=ids, name=name)(
scope
)
else:
return FixtureFunctionMarker(scope, params, autouse, ids=ids, name=name)
return fixture(scope=scope, params=params, autouse=autouse, ids=ids, name=name)
defaultfuncargprefixmarker = fixture()
@@ -1033,11 +1141,12 @@ class FixtureManager(object):
usefixtures = flatten(
mark.args for mark in node.iter_markers(name="usefixtures")
)
initialnames = argnames
initialnames = tuple(usefixtures) + initialnames
initialnames = tuple(usefixtures) + argnames
fm = node.session._fixturemanager
names_closure, arg2fixturedefs = fm.getfixtureclosure(initialnames, node)
return FuncFixtureInfo(argnames, names_closure, arg2fixturedefs)
initialnames, names_closure, arg2fixturedefs = fm.getfixtureclosure(
initialnames, node
)
return FuncFixtureInfo(argnames, initialnames, names_closure, arg2fixturedefs)
def pytest_plugin_registered(self, plugin):
nodeid = None
@@ -1085,6 +1194,12 @@ class FixtureManager(object):
fixturenames_closure.append(arg)
merge(fixturenames)
# at this point, fixturenames_closure contains what we call "initialnames",
# which is a set of fixturenames the function immediately requests. We
# need to return it as well, so save this.
initialnames = tuple(fixturenames_closure)
arg2fixturedefs = {}
lastlen = -1
while lastlen != len(fixturenames_closure):
@@ -1106,7 +1221,7 @@ class FixtureManager(object):
return fixturedefs[-1].scopenum
fixturenames_closure.sort(key=sort_by_scope)
return fixturenames_closure, arg2fixturedefs
return initialnames, fixturenames_closure, arg2fixturedefs
def pytest_generate_tests(self, metafunc):
for argname in metafunc.fixturenames:
@@ -1142,6 +1257,8 @@ class FixtureManager(object):
items[:] = reorder_items(items)
def parsefactories(self, node_or_obj, nodeid=NOTSET, unittest=False):
from _pytest import deprecated
if nodeid is not NOTSET:
holderobj = node_or_obj
else:
@@ -1155,19 +1272,24 @@ class FixtureManager(object):
# The attribute can be an arbitrary descriptor, so the attribute
# access below can raise. safe_getatt() ignores such exceptions.
obj = safe_getattr(holderobj, name, None)
marker = getfixturemarker(obj)
# fixture functions have a pytest_funcarg__ prefix (pre-2.3 style)
# or are "@pytest.fixture" marked
marker = getfixturemarker(obj)
if marker is None:
if not name.startswith(self._argprefix):
continue
if not callable(obj):
continue
marker = defaultfuncargprefixmarker
from _pytest import deprecated
self.config.warn(
"C1", deprecated.FUNCARG_PREFIX.format(name=name), nodeid=nodeid
filename, lineno = getfslineno(obj)
warnings.warn_explicit(
RemovedInPytest4Warning(
deprecated.FUNCARG_PREFIX.format(name=name)
),
category=None,
filename=str(filename),
lineno=lineno + 1,
)
name = name[len(self._argprefix) :]
elif not isinstance(marker, FixtureFunctionMarker):
@@ -1179,6 +1301,15 @@ class FixtureManager(object):
name = marker.name
assert not name.startswith(self._argprefix), FIXTURE_MSG.format(name)
# during fixture definition we wrap the original fixture function
# to issue a warning if called directly, so here we unwrap it in order to not emit the warning
# when pytest itself calls the fixture function
if six.PY2 and unittest:
# hack on Python 2 because of the unbound methods
obj = get_real_func(obj)
else:
obj = get_real_method(obj, holderobj)
fixture_def = FixtureDef(
self,
nodeid,

View File

@@ -156,6 +156,7 @@ def showhelp(config):
vars = [
("PYTEST_ADDOPTS", "extra command line options"),
("PYTEST_PLUGINS", "comma-separated plugins to load during startup"),
("PYTEST_DISABLE_PLUGIN_AUTOLOAD", "set to disable plugin auto-loading"),
("PYTEST_DEBUG", "set to enable debug tracing of pytest's internals"),
]
for name, help in vars:

View File

@@ -1,6 +1,8 @@
""" hook specifications for pytest plugins, invoked from main.py and builtin plugins. """
from pluggy import HookspecMarker
from .deprecated import PYTEST_NAMESPACE
hookspec = HookspecMarker("pytest")
@@ -22,10 +24,9 @@ def pytest_addhooks(pluginmanager):
"""
@hookspec(historic=True)
@hookspec(historic=True, warn_on_impl=PYTEST_NAMESPACE)
def pytest_namespace():
"""
(**Deprecated**) this hook causes direct monkeypatching on pytest, its use is strongly discouraged
return dict of name->object to be made globally available in
the pytest namespace.
@@ -33,6 +34,19 @@ def pytest_namespace():
.. note::
This hook is incompatible with ``hookwrapper=True``.
.. warning::
This hook has been **deprecated** and will be removed in pytest 4.0.
Plugins whose users depend on the current namespace functionality should prepare to migrate to a
namespace they actually own.
To support the migration its suggested to trigger ``DeprecationWarnings`` for objects they put into the
pytest namespace.
An stopgap measure to avoid the warning is to monkeypatch the ``pytest`` module, but just as the
``pytest_namespace`` hook this should be seen as a temporary measure to be removed in future versions after
an appropriate transition period.
"""
@@ -512,7 +526,17 @@ def pytest_terminal_summary(terminalreporter, exitstatus):
@hookspec(historic=True)
def pytest_logwarning(message, code, nodeid, fslocation):
""" process a warning specified by a message, a code string,
"""
.. deprecated:: 3.8
This hook is will stop working in a future release.
pytest no longer triggers this hook, but the
terminal writer still implements it to display warnings issued by
:meth:`_pytest.config.Config.warn` and :meth:`_pytest.nodes.Node.warn`. Calling those functions will be
an error in future releases.
process a warning specified by a message, a code string,
a nodeid and fslocation (both of which may be None
if the warning is not tied to a particular node/location).
@@ -521,6 +545,30 @@ def pytest_logwarning(message, code, nodeid, fslocation):
"""
@hookspec(historic=True)
def pytest_warning_captured(warning_message, when, item):
"""
Process a warning captured by the internal pytest warnings plugin.
:param warnings.WarningMessage warning_message:
The captured warning. This is the same object produced by :py:func:`warnings.catch_warnings`, and contains
the same attributes as the parameters of :py:func:`warnings.showwarning`.
:param str when:
Indicates when the warning was captured. Possible values:
* ``"config"``: during pytest configuration/initialization stage.
* ``"collect"``: during test collection.
* ``"runtest"``: during test execution.
:param pytest.Item|None item:
**DEPRECATED**: This parameter is incompatible with ``pytest-xdist``, and will always receive ``None``
in a future release.
The item being executed if ``when`` is ``"runtest"``, otherwise ``None``.
"""
# -------------------------------------------------------------------------
# doctest hooks
# -------------------------------------------------------------------------

View File

@@ -258,12 +258,11 @@ def record_property(request):
@pytest.fixture
def record_xml_property(record_property):
def record_xml_property(record_property, request):
"""(Deprecated) use record_property."""
import warnings
from _pytest import deprecated
warnings.warn(deprecated.RECORD_XML_PROPERTY, DeprecationWarning, stacklevel=2)
request.node.warn(deprecated.RECORD_XML_PROPERTY)
return record_property
@@ -274,9 +273,9 @@ def record_xml_attribute(request):
The fixture is callable with ``(name, value)``, with value being
automatically xml-encoded
"""
request.node.warn(
code="C3", message="record_xml_attribute is an experimental feature"
)
from _pytest.warning_types import PytestWarning
request.node.warn(PytestWarning("record_xml_attribute is an experimental feature"))
xml = getattr(request.config, "_xml", None)
if xml is not None:
node_reporter = xml.node_reporter(request.node.nodeid)

View File

@@ -6,6 +6,7 @@ from contextlib import closing, contextmanager
import re
import six
from _pytest.compat import dummy_context_manager
from _pytest.config import create_terminal_writer
import pytest
import py
@@ -270,6 +271,22 @@ class LogCaptureFixture(object):
"""
return [(r.name, r.levelno, r.getMessage()) for r in self.records]
@property
def messages(self):
"""Returns a list of format-interpolated log messages.
Unlike 'records', which contains the format string and parameters for interpolation, log messages in this list
are all interpolated.
Unlike 'text', which contains the output from the handler, log messages in this list are unadorned with
levels, timestamps, etc, making exact comparisions more reliable.
Note that traceback or stack info (from :func:`logging.exception` or the `exc_info` or `stack_info` arguments
to the logging functions) is not included, as this is added by the formatter in the handler.
.. versionadded:: 3.7
"""
return [r.getMessage() for r in self.records]
def clear(self):
"""Reset the list of log records and the captured log text."""
self.handler.reset()
@@ -353,11 +370,6 @@ def pytest_configure(config):
config.pluginmanager.register(LoggingPlugin(config), "logging-plugin")
@contextmanager
def _dummy_context_manager():
yield
class LoggingPlugin(object):
"""Attaches to the logging module and captures log messages for each test.
"""
@@ -433,8 +445,8 @@ class LoggingPlugin(object):
try:
yield # run test
finally:
del item.catch_log_handler
if when == "teardown":
del item.catch_log_handler
del item.catch_log_handlers
if self.print_logs:
@@ -521,7 +533,7 @@ class LoggingPlugin(object):
log_cli_handler, formatter=log_cli_formatter, level=log_cli_level
)
else:
self.live_logs_context = _dummy_context_manager()
self.live_logs_context = dummy_context_manager()
class _LiveLoggingStreamHandler(logging.StreamHandler):
@@ -556,9 +568,12 @@ class _LiveLoggingStreamHandler(logging.StreamHandler):
self._test_outcome_written = False
def emit(self, record):
if self.capture_manager is not None:
self.capture_manager.suspend_global_capture()
try:
ctx_manager = (
self.capture_manager.global_and_fixture_disabled()
if self.capture_manager
else dummy_context_manager()
)
with ctx_manager:
if not self._first_record_emitted:
self.stream.write("\n")
self._first_record_emitted = True
@@ -570,6 +585,3 @@ class _LiveLoggingStreamHandler(logging.StreamHandler):
self.stream.section("live log " + self._when, sep="-", bold=True)
self._section_name_shown = True
logging.StreamHandler.emit(self, record)
finally:
if self.capture_manager is not None:
self.capture_manager.resume_global_capture()

View File

@@ -383,6 +383,9 @@ class Session(nodes.FSCollector):
self.trace = config.trace.root.get("collection")
self._norecursepatterns = config.getini("norecursedirs")
self.startdir = py.path.local()
self._initialpaths = frozenset()
# Keep track of any collected nodes in here, so we don't duplicate fixtures
self._node_cache = {}
self.config.pluginmanager.register(self, name="session")
@@ -439,13 +442,14 @@ class Session(nodes.FSCollector):
self.trace("perform_collect", self, args)
self.trace.root.indent += 1
self._notfound = []
self._initialpaths = set()
initialpaths = []
self._initialparts = []
self.items = items = []
for arg in args:
parts = self._parsearg(arg)
self._initialparts.append(parts)
self._initialpaths.add(parts[0])
initialpaths.append(parts[0])
self._initialpaths = frozenset(initialpaths)
rep = collect_one_node(self)
self.ihook.pytest_collectreport(report=rep)
self.trace.root.indent -= 1
@@ -480,19 +484,66 @@ class Session(nodes.FSCollector):
self.trace.root.indent -= 1
def _collect(self, arg):
from _pytest.python import Package
names = self._parsearg(arg)
path = names.pop(0)
if path.check(dir=1):
argpath = names.pop(0)
paths = []
root = self
# Start with a Session root, and delve to argpath item (dir or file)
# and stack all Packages found on the way.
# No point in finding packages when collecting doctests
if not self.config.option.doctestmodules:
for parent in argpath.parts():
pm = self.config.pluginmanager
if pm._confcutdir and pm._confcutdir.relto(parent):
continue
if parent.isdir():
pkginit = parent.join("__init__.py")
if pkginit.isfile():
if pkginit in self._node_cache:
root = self._node_cache[pkginit][0]
else:
col = root._collectfile(pkginit)
if col:
if isinstance(col[0], Package):
root = col[0]
# always store a list in the cache, matchnodes expects it
self._node_cache[root.fspath] = [root]
# If it's a directory argument, recurse and look for any Subpackages.
# Let the Package collector deal with subnodes, don't collect here.
if argpath.check(dir=1):
assert not names, "invalid arg %r" % (arg,)
for path in path.visit(
for path in argpath.visit(
fil=lambda x: x.check(file=1), rec=self._recurse, bf=True, sort=True
):
for x in self._collectfile(path):
yield x
pkginit = path.dirpath().join("__init__.py")
if pkginit.exists() and not any(x in pkginit.parts() for x in paths):
for x in root._collectfile(pkginit):
yield x
paths.append(x.fspath.dirpath())
if not any(x in path.parts() for x in paths):
for x in root._collectfile(path):
if (type(x), x.fspath) in self._node_cache:
yield self._node_cache[(type(x), x.fspath)]
else:
self._node_cache[(type(x), x.fspath)] = x
yield x
else:
assert path.check(file=1)
for x in self.matchnodes(self._collectfile(path), names):
yield x
assert argpath.check(file=1)
if argpath in self._node_cache:
col = self._node_cache[argpath]
else:
col = root._collectfile(argpath)
if col:
self._node_cache[argpath] = col
for y in self.matchnodes(col, names):
yield y
def _collectfile(self, path):
ihook = self.gethookproxy(path)
@@ -516,7 +567,6 @@ class Session(nodes.FSCollector):
"""Convert a dotted module name to path.
"""
try:
with _patched_find_module():
loader = pkgutil.find_loader(x)
@@ -577,7 +627,12 @@ class Session(nodes.FSCollector):
resultnodes.append(node)
continue
assert isinstance(node, nodes.Collector)
rep = collect_one_node(node)
key = (type(node), node.nodeid)
if key in self._node_cache:
rep = self._node_cache[key]
else:
rep = collect_one_node(node)
self._node_cache[key] = rep
if rep.passed:
has_matched = False
for x in rep.result:

View File

@@ -66,7 +66,10 @@ python_keywords_allowed_list = ["or", "and", "not"]
def matchmark(colitem, markexpr):
"""Tries to match on any marker names, attached to the given colitem."""
return eval(markexpr, {}, MarkMapping.from_item(colitem))
try:
return eval(markexpr, {}, MarkMapping.from_item(colitem))
except SyntaxError as e:
raise SyntaxError(str(e) + "\nMarker expression must be valid Python!")
def matchkeyword(colitem, keywordexpr):

View File

@@ -65,7 +65,7 @@ class ParameterSet(namedtuple("ParameterSet", "values, marks, id")):
return cls(values, marks, id_)
@classmethod
def extract_from(cls, parameterset, legacy_force_tuple=False):
def extract_from(cls, parameterset, belonging_definition, legacy_force_tuple=False):
"""
:param parameterset:
a legacy style parameterset that may or may not be a tuple,
@@ -75,6 +75,7 @@ class ParameterSet(namedtuple("ParameterSet", "values, marks, id")):
enforce tuple wrapping so single argument tuple values
don't get decomposed and break tests
:param belonging_definition: the item that we will be extracting the parameters from.
"""
if isinstance(parameterset, cls):
@@ -93,20 +94,24 @@ class ParameterSet(namedtuple("ParameterSet", "values, marks, id")):
if legacy_force_tuple:
argval = (argval,)
if newmarks:
warnings.warn(MARK_PARAMETERSET_UNPACKING)
if newmarks and belonging_definition is not None:
belonging_definition.warn(MARK_PARAMETERSET_UNPACKING)
return cls(argval, marks=newmarks, id=None)
@classmethod
def _for_parametrize(cls, argnames, argvalues, func, config):
def _for_parametrize(cls, argnames, argvalues, func, config, function_definition):
if not isinstance(argnames, (tuple, list)):
argnames = [x.strip() for x in argnames.split(",") if x.strip()]
force_tuple = len(argnames) == 1
else:
force_tuple = False
parameters = [
ParameterSet.extract_from(x, legacy_force_tuple=force_tuple)
ParameterSet.extract_from(
x,
legacy_force_tuple=force_tuple,
belonging_definition=function_definition,
)
for x in argvalues
]
del argvalues

View File

@@ -4,9 +4,12 @@ from __future__ import absolute_import, division, print_function
import os
import sys
import re
import warnings
from contextlib import contextmanager
import six
import pytest
from _pytest.fixtures import fixture
RE_IMPORT_ERROR_NAME = re.compile("^No module named (.*)$")
@@ -209,22 +212,41 @@ class MonkeyPatch(object):
self._setitem.append((dic, name, dic.get(name, notset)))
del dic[name]
def _warn_if_env_name_is_not_str(self, name):
"""On Python 2, warn if the given environment variable name is not a native str (#4056)"""
if six.PY2 and not isinstance(name, str):
warnings.warn(
pytest.PytestWarning(
"Environment variable name {!r} should be str".format(name)
)
)
def setenv(self, name, value, prepend=None):
""" Set environment variable ``name`` to ``value``. If ``prepend``
is a character, read the current environment variable value
and prepend the ``value`` adjoined with the ``prepend`` character."""
value = str(value)
if not isinstance(value, str):
warnings.warn(
pytest.PytestWarning(
"Environment variable value {!r} should be str, converted to str implicitly".format(
value
)
)
)
value = str(value)
if prepend and name in os.environ:
value = value + prepend + os.environ[name]
self._warn_if_env_name_is_not_str(name)
self.setitem(os.environ, name, value)
def delenv(self, name, raising=True):
""" Delete ``name`` from the environment. Raise KeyError it does not
exist.
""" Delete ``name`` from the environment. Raise KeyError if it does
not exist.
If ``raising`` is set to False, no exception will be raised if the
environment variable is missing.
"""
self._warn_if_env_name_is_not_str(name)
self.delitem(os.environ, name, raising=raising)
def syspath_prepend(self, path):

View File

@@ -1,5 +1,6 @@
from __future__ import absolute_import, division, print_function
import os
import warnings
import six
import py
@@ -7,6 +8,7 @@ import attr
import _pytest
import _pytest._code
from _pytest.compat import getfslineno
from _pytest.mark.structures import NodeKeywords, MarkInfo
@@ -134,19 +136,98 @@ class Node(object):
def __repr__(self):
return "<%s %r>" % (self.__class__.__name__, getattr(self, "name", None))
def warn(self, code, message):
""" generate a warning with the given code and message for this
item. """
def warn(self, _code_or_warning=None, message=None, code=None):
"""Issue a warning for this item.
Warnings will be displayed after the test session, unless explicitly suppressed.
This can be called in two forms:
**Warning instance**
This was introduced in pytest 3.8 and uses the standard warning mechanism to issue warnings.
.. code-block:: python
node.warn(PytestWarning("some message"))
The warning instance must be a subclass of :class:`pytest.PytestWarning`.
**code/message (deprecated)**
This form was used in pytest prior to 3.8 and is considered deprecated. Using this form will emit another
warning about the deprecation:
.. code-block:: python
node.warn("CI", "some message")
:param Union[Warning,str] _code_or_warning:
warning instance or warning code (legacy). This parameter receives an underscore for backward
compatibility with the legacy code/message form, and will be replaced for something
more usual when the legacy form is removed.
:param Union[str,None] message: message to display when called in the legacy form.
:param str code: code for the warning, in legacy form when using keyword arguments.
:return:
"""
if message is None:
if _code_or_warning is None:
raise ValueError("code_or_warning must be given")
self._std_warn(_code_or_warning)
else:
if _code_or_warning and code:
raise ValueError(
"code_or_warning and code cannot both be passed to this function"
)
code = _code_or_warning or code
self._legacy_warn(code, message)
def _legacy_warn(self, code, message):
"""
.. deprecated:: 3.8
Use :meth:`Node.std_warn <_pytest.nodes.Node.std_warn>` instead.
Generate a warning with the given code and message for this item.
"""
from _pytest.deprecated import NODE_WARN
self._std_warn(NODE_WARN)
assert isinstance(code, str)
fslocation = getattr(self, "location", None)
if fslocation is None:
fslocation = getattr(self, "fspath", None)
fslocation = get_fslocation_from_item(self)
self.ihook.pytest_logwarning.call_historic(
kwargs=dict(
code=code, message=message, nodeid=self.nodeid, fslocation=fslocation
)
)
def _std_warn(self, warning):
"""Issue a warning for this item.
Warnings will be displayed after the test session, unless explicitly suppressed
:param Warning warning: the warning instance to issue. Must be a subclass of PytestWarning.
:raise ValueError: if ``warning`` instance is not a subclass of PytestWarning.
"""
from _pytest.warning_types import PytestWarning
if not isinstance(warning, PytestWarning):
raise ValueError(
"warning must be an instance of PytestWarning or subclass, got {!r}".format(
warning
)
)
path, lineno = get_fslocation_from_item(self)
warnings.warn_explicit(
warning,
category=None,
filename=str(path),
lineno=lineno + 1 if lineno is not None else None,
)
# methods for ordering nodes
@property
def nodeid(self):
@@ -173,10 +254,13 @@ class Node(object):
chain.reverse()
return chain
def add_marker(self, marker):
def add_marker(self, marker, append=True):
"""dynamically add a marker object to the node.
:type marker: str or pytest.mark.*
:type marker: ``str`` or ``pytest.mark.*`` object
:param marker:
``append=True`` whether to append the marker,
if ``False`` insert at position ``0``.
"""
from _pytest.mark import MarkDecorator, MARK_GEN
@@ -185,7 +269,10 @@ class Node(object):
elif not isinstance(marker, MarkDecorator):
raise ValueError("is not a string or pytest.mark.* Marker")
self.keywords[marker.name] = marker
self.own_markers.append(marker.mark)
if append:
self.own_markers.append(marker.mark)
else:
self.own_markers.insert(0, marker.mark)
def iter_markers(self, name=None):
"""
@@ -281,6 +368,11 @@ class Node(object):
else:
style = "long"
if self.config.option.verbose > 1:
truncate_locals = False
else:
truncate_locals = True
try:
os.getcwd()
abspath = False
@@ -293,11 +385,30 @@ class Node(object):
showlocals=self.config.option.showlocals,
style=style,
tbfilter=tbfilter,
truncate_locals=truncate_locals,
)
repr_failure = _repr_failure_py
def get_fslocation_from_item(item):
"""Tries to extract the actual location from an item, depending on available attributes:
* "fslocation": a pair (path, lineno)
* "obj": a Python object that the item wraps.
* "fspath": just a path
:rtype: a tuple of (str|LocalPath, int) with filename and line number.
"""
result = getattr(item, "location", None)
if result is not None:
return result[:2]
obj = getattr(item, "obj", None)
if obj is not None:
return getfslineno(obj)
return getattr(item, "fspath", "unknown location"), -1
class Collector(Node):
""" Collector instances create children through collect()
and thus iteratively build a tree.
@@ -352,7 +463,7 @@ class FSCollector(Collector):
if not nodeid:
nodeid = _check_initialpaths_for_relpath(session, fspath)
if os.sep != SEP:
if nodeid and os.sep != SEP:
nodeid = nodeid.replace(os.sep, SEP)
super(FSCollector, self).__init__(

View File

@@ -3,7 +3,6 @@ exception classes and constants handling test outcomes
as well as functions creating them
"""
from __future__ import absolute_import, division, print_function
import py
import sys
@@ -21,7 +20,7 @@ class OutcomeException(BaseException):
if self.msg:
val = self.msg
if isinstance(val, bytes):
val = py._builtin._totext(val, errors="replace")
val = val.decode("UTF-8", errors="replace")
return val
return "<%s instance>" % (self.__class__.__name__,)
@@ -68,13 +67,19 @@ exit.Exception = Exit
def skip(msg="", **kwargs):
""" 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
skipped under certain conditions like mismatching platforms or
dependencies. See the pytest_skipping plugin for details.
"""
Skip an executing test with the given message.
This function should be called only during testing (setup, call or teardown) or
during collection by using the ``allow_module_level`` flag.
:kwarg bool allow_module_level: allows this function to be called at
module level, skipping the rest of the module. Default to False.
.. note::
It is better to use the :ref:`pytest.mark.skipif ref` marker when possible to declare a test to be
skipped under certain conditions like mismatching platforms or
dependencies.
"""
__tracebackhide__ = True
allow_module_level = kwargs.pop("allow_module_level", False)
@@ -88,10 +93,12 @@ skip.Exception = Skipped
def fail(msg="", pytrace=True):
""" explicitly fail a currently-executing test with the given Message.
"""
Explicitly fail an executing test with the given message.
:arg pytrace: if false the msg represents the full failure information
and no python traceback will be reported.
:param str msg: the message to show the user as reason for the failure.
:param bool pytrace: if false the msg represents the full failure information and no
python traceback will be reported.
"""
__tracebackhide__ = True
raise Failed(msg=msg, pytrace=pytrace)
@@ -105,7 +112,15 @@ class XFailed(fail.Exception):
def xfail(reason=""):
""" xfail an executing test or setup functions with the given reason."""
"""
Imperatively xfail an executing test or setup functions with the given reason.
This function should be called only during testing (setup, call or teardown).
.. note::
It is better to use the :ref:`pytest.mark.xfail ref` marker when possible to declare a test to be
xfailed under certain conditions like known bugs or missing features.
"""
__tracebackhide__ = True
raise XFailed(reason)

52
src/_pytest/paths.py Normal file
View File

@@ -0,0 +1,52 @@
from os.path import expanduser, expandvars, isabs, sep
from posixpath import sep as posix_sep
import fnmatch
import sys
import six
from .compat import Path, PurePath
def resolve_from_str(input, root):
assert not isinstance(input, Path), "would break on py2"
root = Path(root)
input = expanduser(input)
input = expandvars(input)
if isabs(input):
return Path(input)
else:
return root.joinpath(input)
def fnmatch_ex(pattern, path):
"""FNMatcher port from py.path.common which works with PurePath() instances.
The difference between this algorithm and PurePath.match() is that the latter matches "**" glob expressions
for each part of the path, while this algorithm uses the whole path instead.
For example:
"tests/foo/bar/doc/test_foo.py" matches pattern "tests/**/doc/test*.py" with this algorithm, but not with
PurePath.match().
This algorithm was ported to keep backward-compatibility with existing settings which assume paths match according
this logic.
References:
* https://bugs.python.org/issue29249
* https://bugs.python.org/issue34731
"""
path = PurePath(path)
iswin32 = sys.platform.startswith("win")
if iswin32 and sep not in pattern and posix_sep in pattern:
# Running on Windows, the pattern has no Windows path separators,
# and the pattern has one or more Posix path separators. Replace
# the Posix path separators with the Windows path separator.
pattern = pattern.replace(posix_sep, sep)
if sep not in pattern:
name = path.name
else:
name = six.text_type(path)
return fnmatch.fnmatch(name, pattern)

View File

@@ -21,7 +21,8 @@ import py
import pytest
from _pytest.main import Session, EXIT_OK
from _pytest.assertion.rewrite import AssertionRewritingHook
from _pytest.compat import Path
from _pytest.compat import safe_str
IGNORE_PAM = [ # filenames added when obtaining details about the current user
u"/var/lib/sss/mc/passwd"
@@ -34,7 +35,7 @@ def pytest_addoption(parser):
action="store_true",
dest="lsof",
default=False,
help=("run FD checks if lsof is available"),
help="run FD checks if lsof is available",
)
parser.addoption(
@@ -48,6 +49,10 @@ def pytest_addoption(parser):
),
)
parser.addini(
"pytester_example_dir", help="directory to take the pytester example files from"
)
def pytest_configure(config):
if config.getvalue("lsof"):
@@ -121,7 +126,7 @@ class LsofFdLeakChecker(object):
error.append(error[0])
error.append("*** function %s:%s: %s " % item.location)
error.append("See issue #2366")
item.warn("", "\n".join(error))
item.warn(pytest.PytestWarning("\n".join(error)))
# XXX copied from execnet's conftest.py - needs to be merged
@@ -269,7 +274,7 @@ class HookRecorder(object):
del self.calls[i]
return call
lines = ["could not find call %r, in:" % (name,)]
lines.extend([" %s" % str(x) for x in self.calls])
lines.extend([" %s" % x for x in self.calls])
pytest.fail("\n".join(lines))
def getcall(self, name):
@@ -402,7 +407,9 @@ class RunResult(object):
return d
raise ValueError("Pytest terminal report not found")
def assert_outcomes(self, passed=0, skipped=0, failed=0, error=0):
def assert_outcomes(
self, passed=0, skipped=0, failed=0, error=0, xpassed=0, xfailed=0
):
"""Assert that the specified outcomes appear with the respective
numbers (0 means it didn't occur) in the text output from a test run.
@@ -413,10 +420,18 @@ class RunResult(object):
"skipped": d.get("skipped", 0),
"failed": d.get("failed", 0),
"error": d.get("error", 0),
"xpassed": d.get("xpassed", 0),
"xfailed": d.get("xfailed", 0),
}
assert obtained == dict(
passed=passed, skipped=skipped, failed=failed, error=error
)
expected = {
"passed": passed,
"skipped": skipped,
"failed": failed,
"error": error,
"xpassed": xpassed,
"xfailed": xfailed,
}
assert obtained == expected
class CwdSnapshot(object):
@@ -510,7 +525,6 @@ class Testdir(object):
def make_hook_recorder(self, pluginmanager):
"""Create a new :py:class:`HookRecorder` for a PluginManager."""
assert not hasattr(pluginmanager, "reprec")
pluginmanager.reprec = reprec = HookRecorder(pluginmanager)
self.request.addfinalizer(reprec.finish_recording)
return reprec
@@ -546,18 +560,22 @@ class Testdir(object):
return ret
def makefile(self, ext, *args, **kwargs):
"""Create a new file in the testdir.
r"""Create new file(s) in the testdir.
ext: The extension the file should use, including the dot, e.g. `.py`.
args: All args will be treated as strings and joined using newlines.
:param str ext: The extension the file(s) should use, including the dot, e.g. `.py`.
:param list[str] args: All args will be treated as strings and joined using newlines.
The result will be written as contents to the file. The name of the
file will be based on the test function requesting this fixture.
E.g. "testdir.makefile('.txt', 'line1', 'line2')"
kwargs: Each keyword is the name of a file, while the value of it will
:param kwargs: Each keyword is the name of a file, while the value of it will
be written as contents of the file.
E.g. "testdir.makefile('.ini', pytest='[pytest]\naddopts=-rs\n')"
Examples:
.. code-block:: python
testdir.makefile(".txt", "line1", "line2")
testdir.makefile(".ini", pytest="[pytest]\naddopts=-rs\n")
"""
return self._makefile(ext, args, kwargs)
@@ -623,6 +641,50 @@ class Testdir(object):
p.ensure("__init__.py")
return p
def copy_example(self, name=None):
import warnings
from _pytest.warning_types import PYTESTER_COPY_EXAMPLE
warnings.warn(PYTESTER_COPY_EXAMPLE, stacklevel=2)
example_dir = self.request.config.getini("pytester_example_dir")
if example_dir is None:
raise ValueError("pytester_example_dir is unset, can't copy examples")
example_dir = self.request.config.rootdir.join(example_dir)
for extra_element in self.request.node.iter_markers("pytester_example_path"):
assert extra_element.args
example_dir = example_dir.join(*extra_element.args)
if name is None:
func_name = self.request.function.__name__
maybe_dir = example_dir / func_name
maybe_file = example_dir / (func_name + ".py")
if maybe_dir.isdir():
example_path = maybe_dir
elif maybe_file.isfile():
example_path = maybe_file
else:
raise LookupError(
"{} cant be found as module or package in {}".format(
func_name, example_dir.bestrelpath(self.request.confg.rootdir)
)
)
else:
example_path = example_dir.join(name)
if example_path.isdir() and not example_path.join("__init__.py").isfile():
example_path.copy(self.tmpdir)
return self.tmpdir
elif example_path.isfile():
result = self.tmpdir.join(example_path.basename)
example_path.copy(result)
return result
else:
raise LookupError(
'example "{}" is not found as a file or directory'.format(example_path)
)
Session = Session
def getnode(self, config, arg):
@@ -835,14 +897,12 @@ class Testdir(object):
return self._runpytest_method(*args, **kwargs)
def _ensure_basetemp(self, args):
args = [str(x) for x in args]
args = list(args)
for x in args:
if str(x).startswith("--basetemp"):
# print("basedtemp exists: %s" %(args,))
if safe_str(x).startswith("--basetemp"):
break
else:
args.append("--basetemp=%s" % self.tmpdir.dirpath("basetemp"))
# print("added basetemp: %s" %(args,))
return args
def parseconfig(self, *args):
@@ -929,14 +989,16 @@ class Testdir(object):
same directory to ensure it is a package
"""
kw = {self.request.function.__name__: Source(source).strip()}
path = self.makepyfile(**kw)
if isinstance(source, Path):
path = self.tmpdir.join(str(source))
assert not withinit, "not supported for paths"
else:
kw = {self.request.function.__name__: Source(source).strip()}
path = self.makepyfile(**kw)
if withinit:
self.makepyfile(__init__="#")
self.config = config = self.parseconfigure(path, *configargs)
node = self.getnode(config, path)
return node
return self.getnode(config, path)
def collect_by_name(self, modcol, name):
"""Return the collection node for name from the module collection.
@@ -966,7 +1028,7 @@ class Testdir(object):
"""
env = os.environ.copy()
env["PYTHONPATH"] = os.pathsep.join(
filter(None, [str(os.getcwd()), env.get("PYTHONPATH", "")])
filter(None, [os.getcwd(), env.get("PYTHONPATH", "")])
)
kw["env"] = env
@@ -985,14 +1047,13 @@ class Testdir(object):
Returns a :py:class:`RunResult`.
"""
return self._run(*cmdargs)
def _run(self, *cmdargs):
cmdargs = [str(x) for x in cmdargs]
cmdargs = [
str(arg) if isinstance(arg, py.path.local) else arg for arg in cmdargs
]
p1 = self.tmpdir.join("stdout")
p2 = self.tmpdir.join("stderr")
print("running:", " ".join(cmdargs))
print(" in:", str(py.path.local()))
print("running:", *cmdargs)
print(" in:", py.path.local())
f1 = codecs.open(str(p1), "w", encoding="utf8")
f2 = codecs.open(str(p2), "w", encoding="utf8")
try:
@@ -1024,7 +1085,7 @@ class Testdir(object):
print("couldn't print to %s because of encoding" % (fp,))
def _getpytestargs(self):
return (sys.executable, "-mpytest")
return sys.executable, "-mpytest"
def runpython(self, script):
"""Run a python script using sys.executable as interpreter.

View File

@@ -12,6 +12,7 @@ from textwrap import dedent
import py
import six
from _pytest.main import FSHookProxy
from _pytest.mark import MarkerError
from _pytest.config import hookimpl
@@ -36,6 +37,7 @@ from _pytest.compat import (
getlocation,
enum,
get_default_arg_names,
getimfunc,
)
from _pytest.outcomes import fail
from _pytest.mark.structures import (
@@ -43,7 +45,7 @@ from _pytest.mark.structures import (
get_unpacked_marks,
normalize_mark_list,
)
from _pytest.warning_types import RemovedInPytest4Warning, PytestWarning
# relative paths that we use to filter traceback entries from appearing to the user;
# see filter_traceback
@@ -172,13 +174,14 @@ def pytest_configure(config):
"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.",
"see https://docs.pytest.org/en/latest/parametrize.html for more info "
"and examples.",
)
config.addinivalue_line(
"markers",
"usefixtures(fixturename1, fixturename2, ...): mark tests as needing "
"all of the specified fixtures. see http://pytest.org/latest/fixture.html#usefixtures ",
"all of the specified fixtures. see "
"https://docs.pytest.org/en/latest/fixture.html#usefixtures ",
)
@@ -200,16 +203,22 @@ def pytest_collect_file(path, parent):
ext = path.ext
if ext == ".py":
if not parent.session.isinitpath(path):
for pat in parent.config.getini("python_files"):
if path.fnmatch(pat):
break
else:
if not path_matches_patterns(
path, parent.config.getini("python_files") + ["__init__.py"]
):
return
ihook = parent.session.gethookproxy(path)
return ihook.pytest_pycollect_makemodule(path=path, parent=parent)
def path_matches_patterns(path, patterns):
"""Returns True if the given py.path.local matches one of the patterns in the list of globs given"""
return any(path.fnmatch(pattern) for pattern in patterns)
def pytest_pycollect_makemodule(path, parent):
if path.basename == "__init__.py":
return Package(path, parent)
return Module(path, parent)
@@ -231,9 +240,14 @@ def pytest_pycollect_makeitem(collector, name, obj):
# or a funtools.wrapped.
# We musn't if it's been wrapped with mock.patch (python 2 only)
if not (isfunction(obj) or isfunction(get_real_func(obj))):
collector.warn(
code="C2",
message="cannot collect %r because it is not a function." % name,
filename, lineno = getfslineno(obj)
warnings.warn_explicit(
message=PytestWarning(
"cannot collect %r because it is not a function." % name
),
category=None,
filename=str(filename),
lineno=lineno + 1,
)
elif getattr(obj, "__test__", True):
if is_generator(obj):
@@ -341,11 +355,6 @@ class PyCollector(PyobjMixin, nodes.Collector):
if isinstance(obj, staticmethod):
# static methods need to be unwrapped
obj = safe_getattr(obj, "__func__", False)
if obj is False:
# Python 2.6 wraps in a different way that we won't try to handle
msg = "cannot collect static method %r because it is not a function"
self.warn(code="C2", message=msg % name)
return False
return (
safe_getattr(obj, "__call__", False)
and fixtures.getfixturemarker(obj) is None
@@ -438,6 +447,11 @@ class PyCollector(PyobjMixin, nodes.Collector):
# add funcargs() as fixturedefs to fixtureinfo.arg2fixturedefs
fixtures.add_funcarg_pseudo_fixture_def(self, metafunc, fm)
# add_funcarg_pseudo_fixture_def may have shadowed some fixtures
# with direct parametrization, so make sure we update what the
# function really needs.
fixtureinfo.prune_dependency_tree()
for callspec in metafunc._calls:
subname = "%s[%s]" % (name, callspec.id)
yield Function(
@@ -525,6 +539,92 @@ class Module(nodes.File, PyCollector):
self.addfinalizer(teardown_module)
class Package(Module):
def __init__(self, fspath, parent=None, config=None, session=None, nodeid=None):
session = parent.session
nodes.FSCollector.__init__(
self, fspath, parent=parent, config=config, session=session, nodeid=nodeid
)
self.name = fspath.dirname
self.trace = session.trace
self._norecursepatterns = session._norecursepatterns
self.fspath = fspath
def _recurse(self, path):
ihook = self.gethookproxy(path.dirpath())
if ihook.pytest_ignore_collect(path=path, config=self.config):
return False
for pat in self._norecursepatterns:
if path.check(fnmatch=pat):
return False
ihook = self.gethookproxy(path)
ihook.pytest_collect_directory(path=path, parent=self)
return True
def gethookproxy(self, fspath):
# 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 _collectfile(self, path):
ihook = self.gethookproxy(path)
if not self.isinitpath(path):
if ihook.pytest_ignore_collect(path=path, config=self.config):
return ()
return ihook.pytest_collect_file(path=path, parent=self)
def isinitpath(self, path):
return path in self.session._initialpaths
def collect(self):
# XXX: HACK!
# Before starting to collect any files from this package we need
# to cleanup the duplicate paths added by the session's collect().
# Proper fix is to not track these as duplicates in the first place.
for path in list(self.session.config.pluginmanager._duplicatepaths):
# if path.parts()[:len(self.fspath.dirpath().parts())] == self.fspath.dirpath().parts():
if path.dirname.startswith(self.name):
self.session.config.pluginmanager._duplicatepaths.remove(path)
this_path = self.fspath.dirpath()
init_module = this_path.join("__init__.py")
if init_module.check(file=1) and path_matches_patterns(
init_module, self.config.getini("python_files")
):
yield Module(init_module, self)
pkg_prefixes = set()
for path in this_path.visit(rec=self._recurse, bf=True, sort=True):
# we will visit our own __init__.py file, in which case we skip it
skip = False
if path.basename == "__init__.py" and path.dirpath() == this_path:
continue
for pkg_prefix in pkg_prefixes:
if (
pkg_prefix in path.parts()
and pkg_prefix.join("__init__.py") != path
):
skip = True
if skip:
continue
if path.isdir() and path.join("__init__.py").check(file=1):
pkg_prefixes.add(path)
for x in self._collectfile(path):
yield x
def _get_xunit_setup_teardown(holder, attr_name, param_obj=None):
"""
Return a callable to perform xunit-style setup or teardown if
@@ -563,16 +663,18 @@ class Class(PyCollector):
return []
if hasinit(self.obj):
self.warn(
"C1",
"cannot collect test class %r because it has a "
"__init__ constructor" % self.obj.__name__,
PytestWarning(
"cannot collect test class %r because it has a "
"__init__ constructor" % self.obj.__name__
)
)
return []
elif hasnew(self.obj):
self.warn(
"C1",
"cannot collect test class %r because it has a "
"__new__ constructor" % self.obj.__name__,
PytestWarning(
"cannot collect test class %r because it has a "
"__new__ constructor" % self.obj.__name__
)
)
return []
return [self._getcustomclass("Instance")(name="()", parent=self)]
@@ -580,14 +682,12 @@ class Class(PyCollector):
def setup(self):
setup_class = _get_xunit_func(self.obj, "setup_class")
if setup_class is not None:
setup_class = getattr(setup_class, "im_func", setup_class)
setup_class = getattr(setup_class, "__func__", setup_class)
setup_class = getimfunc(setup_class)
setup_class(self.obj)
fin_class = getattr(self.obj, "teardown_class", None)
if fin_class is not None:
fin_class = getattr(fin_class, "im_func", fin_class)
fin_class = getattr(fin_class, "__func__", fin_class)
fin_class = getimfunc(fin_class)
self.addfinalizer(lambda: fin_class(self.obj))
@@ -663,7 +763,7 @@ class FunctionMixin(PyobjMixin):
def _repr_failure_py(self, excinfo, style="long"):
if excinfo.errisinstance(fail.Exception):
if not excinfo.value.pytrace:
return py._builtin._totext(excinfo.value)
return six.text_type(excinfo.value)
return super(FunctionMixin, self)._repr_failure_py(excinfo, style=style)
def repr_failure(self, excinfo, outerr=None):
@@ -700,7 +800,7 @@ class Generator(FunctionMixin, PyCollector):
)
seen[name] = True
values.append(self.Function(name, self, args=args, callobj=call))
self.warn("C1", deprecated.YIELD_TESTS)
self.warn(deprecated.YIELD_TESTS)
return values
def getcallargs(self, obj):
@@ -800,12 +900,13 @@ class Metafunc(fixtures.FuncargnamesCompatAttr):
"""
def __init__(self, definition, fixtureinfo, config, cls=None, module=None):
#: access to the :class:`_pytest.config.Config` object for the test session
assert (
isinstance(definition, FunctionDefinition)
or type(definition).__name__ == "DefinitionMock"
)
self.definition = definition
#: access to the :class:`_pytest.config.Config` object for the test session
self.config = config
#: the module object where the test function is defined in.
@@ -866,7 +967,11 @@ class Metafunc(fixtures.FuncargnamesCompatAttr):
from _pytest.mark import ParameterSet
argnames, parameters = ParameterSet._for_parametrize(
argnames, argvalues, self.function, self.config
argnames,
argvalues,
self.function,
self.config,
function_definition=self.definition,
)
del argvalues
@@ -877,7 +982,7 @@ class Metafunc(fixtures.FuncargnamesCompatAttr):
arg_values_types = self._resolve_arg_value_types(argnames, indirect)
ids = self._resolve_arg_ids(argnames, ids, parameters)
ids = self._resolve_arg_ids(argnames, ids, parameters, item=self.definition)
scopenum = scope2index(scope, descr="call to {}".format(self.parametrize))
@@ -900,13 +1005,14 @@ class Metafunc(fixtures.FuncargnamesCompatAttr):
newcalls.append(newcallspec)
self._calls = newcalls
def _resolve_arg_ids(self, argnames, ids, parameters):
def _resolve_arg_ids(self, argnames, ids, parameters, item):
"""Resolves the actual ids for the given argnames, based on the ``ids`` parameter given
to ``parametrize``.
:param List[str] argnames: list of argument names passed to ``parametrize()``.
:param ids: the ids parameter of the parametrized call (see docs).
:param List[ParameterSet] parameters: the list of parameter values, same size as ``argnames``.
:param Item item: the item that generated this parametrized call.
:rtype: List[str]
:return: the list of ids for each argname given
"""
@@ -927,7 +1033,7 @@ class Metafunc(fixtures.FuncargnamesCompatAttr):
raise ValueError(
msg % (saferepr(id_value), type(id_value).__name__)
)
ids = idmaker(argnames, parameters, idfn, ids, self.config)
ids = idmaker(argnames, parameters, idfn, ids, self.config, item=item)
return ids
def _resolve_arg_value_types(self, argnames, indirect):
@@ -1000,10 +1106,8 @@ class Metafunc(fixtures.FuncargnamesCompatAttr):
:arg param: a parameter which will be exposed to a later fixture function
invocation through the ``request.param`` attribute.
"""
if self.config:
self.config.warn(
"C1", message=deprecated.METAFUNC_ADD_CALL, fslocation=None
)
warnings.warn(deprecated.METAFUNC_ADD_CALL, stacklevel=2)
assert funcargs is None or isinstance(funcargs, dict)
if funcargs is not None:
for name in funcargs:
@@ -1037,13 +1141,18 @@ def _find_parametrized_scope(argnames, arg2fixturedefs, indirect):
"""
from _pytest.fixtures import scopes
indirect_as_list = isinstance(indirect, (list, tuple))
all_arguments_are_fixtures = (
indirect is True or indirect_as_list and len(indirect) == argnames
)
if isinstance(indirect, (list, tuple)):
all_arguments_are_fixtures = len(indirect) == len(argnames)
else:
all_arguments_are_fixtures = bool(indirect)
if all_arguments_are_fixtures:
fixturedefs = arg2fixturedefs or {}
used_scopes = [fixturedef[0].scope for name, fixturedef in fixturedefs.items()]
used_scopes = [
fixturedef[0].scope
for name, fixturedef in fixturedefs.items()
if name in argnames
]
if used_scopes:
# Takes the most narrow scope from used fixtures
for scope in reversed(scopes):
@@ -1053,21 +1162,20 @@ def _find_parametrized_scope(argnames, arg2fixturedefs, indirect):
return "function"
def _idval(val, argname, idx, idfn, config=None):
def _idval(val, argname, idx, idfn, item, config):
if idfn:
s = None
try:
s = idfn(val)
except Exception:
except Exception as e:
# See issue https://github.com/pytest-dev/pytest/issues/2169
import warnings
msg = (
"Raised while trying to determine id of parameter %s at position %d."
% (argname, idx)
"While trying to determine id of parameter {} at position "
"{} the following exception was raised:\n".format(argname, idx)
)
msg += "\nUpdate your code as this will raise an error in pytest-4.0."
warnings.warn(msg, DeprecationWarning)
msg += " {}: {}\n".format(type(e).__name__, e)
msg += "This warning will be an error error in pytest-4.0."
item.warn(RemovedInPytest4Warning(msg))
if s:
return ascii_escaped(s)
@@ -1091,12 +1199,12 @@ def _idval(val, argname, idx, idfn, config=None):
return str(argname) + str(idx)
def _idvalset(idx, parameterset, argnames, idfn, ids, config=None):
def _idvalset(idx, parameterset, argnames, idfn, ids, item, config):
if parameterset.id is not None:
return parameterset.id
if ids is None or (idx >= len(ids) or ids[idx] is None):
this_id = [
_idval(val, argname, idx, idfn, config)
_idval(val, argname, idx, idfn, item=item, config=config)
for val, argname in zip(parameterset.values, argnames)
]
return "-".join(this_id)
@@ -1104,9 +1212,9 @@ def _idvalset(idx, parameterset, argnames, idfn, ids, config=None):
return ascii_escaped(ids[idx])
def idmaker(argnames, parametersets, idfn=None, ids=None, config=None):
def idmaker(argnames, parametersets, idfn=None, ids=None, config=None, item=None):
ids = [
_idvalset(valindex, parameterset, argnames, idfn, ids, config)
_idvalset(valindex, parameterset, argnames, idfn, ids, config=config, item=item)
for valindex, parameterset in enumerate(parametersets)
]
if len(set(ids)) != len(ids):
@@ -1329,7 +1437,7 @@ class Function(FunctionMixin, nodes.Item, fixtures.FuncargnamesCompatAttr):
@property
def function(self):
"underlying python 'function' object"
return getattr(self.obj, "im_func", self.obj)
return getimfunc(self.obj)
def _getobj(self):
name = self.name

View File

@@ -1,7 +1,10 @@
import math
import pprint
import sys
from numbers import Number
from decimal import Decimal
import py
import six
from six.moves import zip, filterfalse
from more_itertools.more import always_iterable
@@ -30,6 +33,15 @@ def _cmp_raises_type_error(self, other):
)
def _non_numeric_type_error(value, at):
at_str = " at {}".format(at) if at else ""
return TypeError(
"cannot make approximate comparisons to non-numeric values: {!r} {}".format(
value, at_str
)
)
# builtin pytest.approx helper
@@ -39,15 +51,17 @@ class ApproxBase(object):
or sequences of numbers.
"""
# Tell numpy to use our `__eq__` operator instead of its
# Tell numpy to use our `__eq__` operator instead of its.
__array_ufunc__ = None
__array_priority__ = 100
def __init__(self, expected, rel=None, abs=None, nan_ok=False):
__tracebackhide__ = True
self.expected = expected
self.abs = abs
self.rel = rel
self.nan_ok = nan_ok
self._check_type()
def __repr__(self):
raise NotImplementedError
@@ -75,21 +89,32 @@ class ApproxBase(object):
"""
raise NotImplementedError
def _check_type(self):
"""
Raise a TypeError if the expected value is not a valid type.
"""
# This is only a concern if the expected value is a sequence. In every
# other case, the approx() function ensures that the expected value has
# a numeric type. For this reason, the default is to do nothing. The
# classes that deal with sequences should reimplement this method to
# raise if there are any non-numeric elements in the sequence.
pass
def _recursive_list_map(f, x):
if isinstance(x, list):
return list(_recursive_list_map(f, xi) for xi in x)
else:
return f(x)
class ApproxNumpy(ApproxBase):
"""
Perform approximate comparisons for numpy arrays.
Perform approximate comparisons where the expected value is numpy array.
"""
def __repr__(self):
# It might be nice to rewrite this function to account for the
# shape of the array...
import numpy as np
list_scalars = []
for x in np.ndindex(self.expected.shape):
list_scalars.append(self._approx_scalar(np.asscalar(self.expected[x])))
list_scalars = _recursive_list_map(self._approx_scalar, self.expected.tolist())
return "approx({!r})".format(list_scalars)
if sys.version_info[0] == 2:
@@ -128,8 +153,8 @@ class ApproxNumpy(ApproxBase):
class ApproxMapping(ApproxBase):
"""
Perform approximate comparisons for mappings where the values are numbers
(the keys can be anything).
Perform approximate comparisons where the expected value is a mapping with
numeric values (the keys can be anything).
"""
def __repr__(self):
@@ -147,10 +172,20 @@ class ApproxMapping(ApproxBase):
for k in self.expected.keys():
yield actual[k], self.expected[k]
def _check_type(self):
__tracebackhide__ = True
for key, value in self.expected.items():
if isinstance(value, type(self.expected)):
msg = "pytest.approx() does not support nested dictionaries: key={!r} value={!r}\n full mapping={}"
raise TypeError(msg.format(key, value, pprint.pformat(self.expected)))
elif not isinstance(value, Number):
raise _non_numeric_type_error(self.expected, at="key={!r}".format(key))
class ApproxSequence(ApproxBase):
"""
Perform approximate comparisons for sequences of numbers.
Perform approximate comparisons where the expected value is a sequence of
numbers.
"""
def __repr__(self):
@@ -169,10 +204,21 @@ class ApproxSequence(ApproxBase):
def _yield_comparisons(self, actual):
return zip(actual, self.expected)
def _check_type(self):
__tracebackhide__ = True
for index, x in enumerate(self.expected):
if isinstance(x, type(self.expected)):
msg = "pytest.approx() does not support nested data structures: {!r} at index {}\n full sequence: {}"
raise TypeError(msg.format(x, index, pprint.pformat(self.expected)))
elif not isinstance(x, Number):
raise _non_numeric_type_error(
self.expected, at="index {}".format(index)
)
class ApproxScalar(ApproxBase):
"""
Perform approximate comparisons for single numbers only.
Perform approximate comparisons where the expected value is a single number.
"""
DEFAULT_ABSOLUTE_TOLERANCE = 1e-12
@@ -211,7 +257,9 @@ class ApproxScalar(ApproxBase):
the pre-specified tolerance.
"""
if _is_numpy_array(actual):
return ApproxNumpy(actual, self.abs, self.rel, self.nan_ok) == self.expected
# Call ``__eq__()`` manually to prevent infinite-recursion with
# numpy<1.13. See #3748.
return all(self.__eq__(a) for a in actual.flat)
# Short-circuit exact equality.
if actual == self.expected:
@@ -286,7 +334,9 @@ class ApproxScalar(ApproxBase):
class ApproxDecimal(ApproxScalar):
from decimal import Decimal
"""
Perform approximate comparisons where the expected value is a decimal.
"""
DEFAULT_ABSOLUTE_TOLERANCE = Decimal("1e-12")
DEFAULT_RELATIVE_TOLERANCE = Decimal("1e-6")
@@ -445,32 +495,35 @@ def approx(expected, rel=None, abs=None, nan_ok=False):
__ https://docs.python.org/3/reference/datamodel.html#object.__ge__
"""
from decimal import Decimal
# Delegate the comparison to a class that knows how to deal with the type
# of the expected value (e.g. int, float, list, dict, numpy.array, etc).
#
# This architecture is really driven by the need to support numpy arrays.
# The only way to override `==` for arrays without requiring that approx be
# the left operand is to inherit the approx object from `numpy.ndarray`.
# But that can't be a general solution, because it requires (1) numpy to be
# installed and (2) the expected value to be a numpy array. So the general
# solution is to delegate each type of expected value to a different class.
# The primary responsibility of these classes is to implement ``__eq__()``
# and ``__repr__()``. The former is used to actually check if some
# "actual" value is equivalent to the given expected value within the
# allowed tolerance. The latter is used to show the user the expected
# value and tolerance, in the case that a test failed.
#
# This has the advantage that it made it easy to support mapping types
# (i.e. dict). The old code accepted mapping types, but would only compare
# their keys, which is probably not what most people would expect.
# The actual logic for making approximate comparisons can be found in
# ApproxScalar, which is used to compare individual numbers. All of the
# other Approx classes eventually delegate to this class. The ApproxBase
# class provides some convenient methods and overloads, but isn't really
# essential.
if _is_numpy_array(expected):
cls = ApproxNumpy
__tracebackhide__ = True
if isinstance(expected, Decimal):
cls = ApproxDecimal
elif isinstance(expected, Number):
cls = ApproxScalar
elif isinstance(expected, Mapping):
cls = ApproxMapping
elif isinstance(expected, Sequence) and not isinstance(expected, STRING_TYPES):
cls = ApproxSequence
elif isinstance(expected, Decimal):
cls = ApproxDecimal
elif _is_numpy_array(expected):
cls = ApproxNumpy
else:
cls = ApproxScalar
raise _non_numeric_type_error(expected, at=None)
return cls(expected, rel, abs, nan_ok)
@@ -480,17 +533,11 @@ def _is_numpy_array(obj):
Return true if the given object is a numpy array. Make a special effort to
avoid importing numpy unless it's really necessary.
"""
import inspect
for cls in inspect.getmro(type(obj)):
if cls.__module__ == "numpy":
try:
import numpy as np
return isinstance(obj, np.ndarray)
except ImportError:
pass
import sys
np = sys.modules.get("numpy")
if np is not None:
return isinstance(obj, np.ndarray)
return False
@@ -633,8 +680,8 @@ def raises(expected_exception, *args, **kwargs):
# print "raises frame scope: %r" % frame.f_locals
try:
code = _pytest._code.Source(code).compile()
py.builtin.exec_(code, frame.f_globals, loc)
# XXX didn'T mean f_globals == f_locals something special?
six.exec_(code, frame.f_globals, loc)
# XXX didn't mean f_globals == f_locals something special?
# this is destroyed here ...
except expected_exception:
return _pytest._code.ExceptionInfo()

View File

@@ -4,11 +4,11 @@ from __future__ import absolute_import, division, print_function
import inspect
import _pytest._code
import py
import re
import sys
import warnings
import re
import six
from _pytest.fixtures import yield_fixture
from _pytest.outcomes import fail
@@ -130,7 +130,7 @@ def warns(expected_warning, *args, **kwargs):
with WarningsChecker(expected_warning, match_expr=match_expr):
code = _pytest._code.Source(code).compile()
py.builtin.exec_(code, frame.f_globals, loc)
six.exec_(code, frame.f_globals, loc)
else:
func = args[0]
with WarningsChecker(expected_warning, match_expr=match_expr):
@@ -212,6 +212,8 @@ class WarningsChecker(WarningsRecorder):
def __exit__(self, *exc_info):
super(WarningsChecker, self).__exit__(*exc_info)
__tracebackhide__ = True
# only check if we're not currently handling an exception
if all(a is None for a in exc_info):
if self.expected_warning is not None:

196
src/_pytest/reports.py Normal file
View File

@@ -0,0 +1,196 @@
import py
from _pytest._code.code import TerminalRepr
def getslaveinfoline(node):
try:
return node._slaveinfocache
except AttributeError:
d = node.slaveinfo
ver = "%s.%s.%s" % d["version_info"][:3]
node._slaveinfocache = s = "[%s] %s -- Python %s %s" % (
d["id"],
d["sysplatform"],
ver,
d["executable"],
)
return s
class BaseReport(object):
def __init__(self, **kw):
self.__dict__.update(kw)
def toterminal(self, out):
if hasattr(self, "node"):
out.line(getslaveinfoline(self.node))
longrepr = self.longrepr
if longrepr is None:
return
if hasattr(longrepr, "toterminal"):
longrepr.toterminal(out)
else:
try:
out.line(longrepr)
except UnicodeEncodeError:
out.line("<unprintable longrepr>")
def get_sections(self, prefix):
for name, content in self.sections:
if name.startswith(prefix):
yield prefix, content
@property
def longreprtext(self):
"""
Read-only property that returns the full string representation
of ``longrepr``.
.. versionadded:: 3.0
"""
tw = py.io.TerminalWriter(stringio=True)
tw.hasmarkup = False
self.toterminal(tw)
exc = tw.stringio.getvalue()
return exc.strip()
@property
def caplog(self):
"""Return captured log lines, if log capturing is enabled
.. versionadded:: 3.5
"""
return "\n".join(
content for (prefix, content) in self.get_sections("Captured log")
)
@property
def capstdout(self):
"""Return captured text from stdout, if capturing is enabled
.. versionadded:: 3.0
"""
return "".join(
content for (prefix, content) in self.get_sections("Captured stdout")
)
@property
def capstderr(self):
"""Return captured text from stderr, if capturing is enabled
.. versionadded:: 3.0
"""
return "".join(
content for (prefix, content) in self.get_sections("Captured stderr")
)
passed = property(lambda x: x.outcome == "passed")
failed = property(lambda x: x.outcome == "failed")
skipped = property(lambda x: x.outcome == "skipped")
@property
def fspath(self):
return self.nodeid.split("::")[0]
class TestReport(BaseReport):
""" Basic test report object (also used for setup and teardown calls if
they fail).
"""
def __init__(
self,
nodeid,
location,
keywords,
outcome,
longrepr,
when,
sections=(),
duration=0,
user_properties=None,
**extra
):
#: normalized collection node id
self.nodeid = nodeid
#: a (filesystempath, lineno, domaininfo) tuple indicating the
#: actual location of a test item - it might be different from the
#: collected one e.g. if a method is inherited from a different module.
self.location = location
#: a name -> value dictionary containing all keywords and
#: markers associated with a test invocation.
self.keywords = keywords
#: test outcome, always one of "passed", "failed", "skipped".
self.outcome = outcome
#: None or a failure representation.
self.longrepr = longrepr
#: one of 'setup', 'call', 'teardown' to indicate runtest phase.
self.when = when
#: user properties is a list of tuples (name, value) that holds user
#: defined properties of the test
self.user_properties = list(user_properties or [])
#: list of pairs ``(str, str)`` of extra information which needs to
#: marshallable. Used by pytest to add captured text
#: from ``stdout`` and ``stderr``, but may be used by other plugins
#: to add arbitrary information to reports.
self.sections = list(sections)
#: time it took to run just the test
self.duration = duration
self.__dict__.update(extra)
def __repr__(self):
return "<TestReport %r when=%r outcome=%r>" % (
self.nodeid,
self.when,
self.outcome,
)
class TeardownErrorReport(BaseReport):
outcome = "failed"
when = "teardown"
def __init__(self, longrepr, **extra):
self.longrepr = longrepr
self.sections = []
self.__dict__.update(extra)
class CollectReport(BaseReport):
def __init__(self, nodeid, outcome, longrepr, result, sections=(), **extra):
self.nodeid = nodeid
self.outcome = outcome
self.longrepr = longrepr
self.result = result or []
self.sections = list(sections)
self.__dict__.update(extra)
@property
def location(self):
return (self.fspath, None, self.fspath)
def __repr__(self):
return "<CollectReport %r lenresult=%s outcome=%r>" % (
self.nodeid,
len(self.result),
self.outcome,
)
class CollectErrorRepr(TerminalRepr):
def __init__(self, msg):
self.longrepr = msg
def toterminal(self, out):
out.line(self.longrepr, red=True)

View File

@@ -31,8 +31,10 @@ def pytest_configure(config):
config.pluginmanager.register(config._resultlog)
from _pytest.deprecated import RESULT_LOG
from _pytest.warning_types import RemovedInPytest4Warning
from _pytest.warnings import _issue_config_warning
config.warn("C1", RESULT_LOG)
_issue_config_warning(RemovedInPytest4Warning(RESULT_LOG), config)
def pytest_unconfigure(config):

View File

@@ -6,10 +6,12 @@ import os
import sys
from time import time
import py
from _pytest._code.code import TerminalRepr, ExceptionInfo
import six
from _pytest._code.code import ExceptionInfo
from _pytest.outcomes import skip, Skipped, TEST_OUTCOME
from .reports import TestReport, CollectReport, CollectErrorRepr
#
# pytest plugin hooks
@@ -215,99 +217,6 @@ class CallInfo(object):
return "<CallInfo when=%r %s>" % (self.when, status)
def getslaveinfoline(node):
try:
return node._slaveinfocache
except AttributeError:
d = node.slaveinfo
ver = "%s.%s.%s" % d["version_info"][:3]
node._slaveinfocache = s = "[%s] %s -- Python %s %s" % (
d["id"],
d["sysplatform"],
ver,
d["executable"],
)
return s
class BaseReport(object):
def __init__(self, **kw):
self.__dict__.update(kw)
def toterminal(self, out):
if hasattr(self, "node"):
out.line(getslaveinfoline(self.node))
longrepr = self.longrepr
if longrepr is None:
return
if hasattr(longrepr, "toterminal"):
longrepr.toterminal(out)
else:
try:
out.line(longrepr)
except UnicodeEncodeError:
out.line("<unprintable longrepr>")
def get_sections(self, prefix):
for name, content in self.sections:
if name.startswith(prefix):
yield prefix, content
@property
def longreprtext(self):
"""
Read-only property that returns the full string representation
of ``longrepr``.
.. versionadded:: 3.0
"""
tw = py.io.TerminalWriter(stringio=True)
tw.hasmarkup = False
self.toterminal(tw)
exc = tw.stringio.getvalue()
return exc.strip()
@property
def caplog(self):
"""Return captured log lines, if log capturing is enabled
.. versionadded:: 3.5
"""
return "\n".join(
content for (prefix, content) in self.get_sections("Captured log")
)
@property
def capstdout(self):
"""Return captured text from stdout, if capturing is enabled
.. versionadded:: 3.0
"""
return "".join(
content for (prefix, content) in self.get_sections("Captured stdout")
)
@property
def capstderr(self):
"""Return captured text from stderr, if capturing is enabled
.. versionadded:: 3.0
"""
return "".join(
content for (prefix, content) in self.get_sections("Captured stderr")
)
passed = property(lambda x: x.outcome == "passed")
failed = property(lambda x: x.outcome == "failed")
skipped = property(lambda x: x.outcome == "skipped")
@property
def fspath(self):
return self.nodeid.split("::")[0]
def pytest_runtest_makereport(item, call):
when = call.when
duration = call.stop - call.start
@@ -348,78 +257,6 @@ def pytest_runtest_makereport(item, call):
)
class TestReport(BaseReport):
""" Basic test report object (also used for setup and teardown calls if
they fail).
"""
def __init__(
self,
nodeid,
location,
keywords,
outcome,
longrepr,
when,
sections=(),
duration=0,
user_properties=(),
**extra
):
#: normalized collection node id
self.nodeid = nodeid
#: a (filesystempath, lineno, domaininfo) tuple indicating the
#: actual location of a test item - it might be different from the
#: collected one e.g. if a method is inherited from a different module.
self.location = location
#: a name -> value dictionary containing all keywords and
#: markers associated with a test invocation.
self.keywords = keywords
#: test outcome, always one of "passed", "failed", "skipped".
self.outcome = outcome
#: None or a failure representation.
self.longrepr = longrepr
#: one of 'setup', 'call', 'teardown' to indicate runtest phase.
self.when = when
#: user properties is a list of tuples (name, value) that holds user
#: defined properties of the test
self.user_properties = user_properties
#: list of pairs ``(str, str)`` of extra information which needs to
#: marshallable. Used by pytest to add captured text
#: from ``stdout`` and ``stderr``, but may be used by other plugins
#: to add arbitrary information to reports.
self.sections = list(sections)
#: time it took to run just the test
self.duration = duration
self.__dict__.update(extra)
def __repr__(self):
return "<TestReport %r when=%r outcome=%r>" % (
self.nodeid,
self.when,
self.outcome,
)
class TeardownErrorReport(BaseReport):
outcome = "failed"
when = "teardown"
def __init__(self, longrepr, **extra):
self.longrepr = longrepr
self.sections = []
self.__dict__.update(extra)
def pytest_make_collect_report(collector):
call = CallInfo(lambda: list(collector.collect()), "collect")
longrepr = None
@@ -446,35 +283,6 @@ def pytest_make_collect_report(collector):
return rep
class CollectReport(BaseReport):
def __init__(self, nodeid, outcome, longrepr, result, sections=(), **extra):
self.nodeid = nodeid
self.outcome = outcome
self.longrepr = longrepr
self.result = result or []
self.sections = list(sections)
self.__dict__.update(extra)
@property
def location(self):
return (self.fspath, None, self.fspath)
def __repr__(self):
return "<CollectReport %r lenresult=%s outcome=%r>" % (
self.nodeid,
len(self.result),
self.outcome,
)
class CollectErrorRepr(TerminalRepr):
def __init__(self, msg):
self.longrepr = msg
def toterminal(self, out):
out.line(self.longrepr, red=True)
class SetupState(object):
""" shared state for setting up/tearing down test items or collectors. """
@@ -509,7 +317,7 @@ class SetupState(object):
if exc is None:
exc = sys.exc_info()
if exc:
py.builtin._reraise(*exc)
six.reraise(*exc)
def _teardown_with_finalization(self, colitem):
self._callfinalizers(colitem)
@@ -544,7 +352,7 @@ class SetupState(object):
if exc is None:
exc = sys.exc_info()
if exc:
py.builtin._reraise(*exc)
six.reraise(*exc)
def prepare(self, colitem):
""" setup objects along the collector chain to the test-method
@@ -555,7 +363,7 @@ class SetupState(object):
# check if the last collection node has raised an error
for col in self.stack:
if hasattr(col, "_prepare_exc"):
py.builtin._reraise(*col._prepare_exc)
six.reraise(*col._prepare_exc)
for col in needed_collectors[len(self.stack) :]:
self.stack.append(col)
try:

View File

@@ -51,7 +51,8 @@ def _show_fixture_action(fixturedef, msg):
config = fixturedef._fixturemanager.config
capman = config.pluginmanager.getplugin("capturemanager")
if capman:
out, err = capman.suspend_global_capture()
capman.suspend_global_capture()
out, err = capman.read_global_capture()
tw = config.get_terminal_writer()
tw.line()

View File

@@ -51,7 +51,7 @@ def pytest_configure(config):
"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",
"https://docs.pytest.org/en/latest/skipping.html",
)
config.addinivalue_line(
"markers",
@@ -61,7 +61,7 @@ def pytest_configure(config):
"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",
"a true failure. See https://docs.pytest.org/en/latest/skipping.html",
)

View File

@@ -9,6 +9,7 @@ import platform
import sys
import time
import attr
import pluggy
import py
import six
@@ -184,23 +185,23 @@ def pytest_report_teststatus(report):
return report.outcome, letter, report.outcome.upper()
@attr.s
class WarningReport(object):
"""
Simple structure to hold warnings information captured by ``pytest_logwarning``.
Simple structure to hold warnings information captured by ``pytest_logwarning`` and ``pytest_warning_captured``.
:ivar str message: user friendly message about the warning
:ivar str|None nodeid: node id that generated the warning (see ``get_location``).
:ivar tuple|py.path.local fslocation:
file system location of the source of the warning (see ``get_location``).
:ivar bool legacy: if this warning report was generated from the deprecated ``pytest_logwarning`` hook.
"""
def __init__(self, code, message, nodeid=None, fslocation=None):
"""
:param code: unused
:param str message: user friendly message about the warning
:param str|None nodeid: node id that generated the warning (see ``get_location``).
:param tuple|py.path.local fslocation:
file system location of the source of the warning (see ``get_location``).
"""
self.code = code
self.message = message
self.nodeid = nodeid
self.fslocation = fslocation
message = attr.ib()
nodeid = attr.ib(default=None)
fslocation = attr.ib(default=None)
legacy = attr.ib(default=False)
def get_location(self, config):
"""
@@ -213,6 +214,8 @@ class WarningReport(object):
if isinstance(self.fslocation, tuple) and len(self.fslocation) >= 2:
filename, linenum = self.fslocation[:2]
relpath = py.path.local(filename).relto(config.invocation_dir)
if not relpath:
relpath = str(filename)
return "%s:%s" % (relpath, linenum)
else:
return str(self.fslocation)
@@ -254,7 +257,7 @@ class TerminalReporter(object):
# do not show progress if we are showing fixture setup/teardown
if self.config.getoption("setupshow"):
return False
return self.config.getini("console_output_style") == "progress"
return self.config.getini("console_output_style") in ("progress", "count")
def hasopt(self, char):
char = {"xfailed": "x", "skipped": "s"}.get(char, char)
@@ -263,7 +266,7 @@ class TerminalReporter(object):
def write_fspath_result(self, nodeid, res):
fspath = self.config.rootdir.join(nodeid.split("::")[0])
if fspath != self.currentfspath:
if self.currentfspath is not None:
if self.currentfspath is not None and self._show_progress_info:
self._write_progress_information_filling_space()
self.currentfspath = fspath
fspath = self.startdir.bestrelpath(fspath)
@@ -327,13 +330,27 @@ class TerminalReporter(object):
self.write_line("INTERNALERROR> " + line)
return 1
def pytest_logwarning(self, code, fslocation, message, nodeid):
def pytest_logwarning(self, fslocation, message, nodeid):
warnings = self.stats.setdefault("warnings", [])
warning = WarningReport(
code=code, fslocation=fslocation, message=message, nodeid=nodeid
fslocation=fslocation, message=message, nodeid=nodeid, legacy=True
)
warnings.append(warning)
def pytest_warning_captured(self, warning_message, item):
# from _pytest.nodes import get_fslocation_from_item
from _pytest.warnings import warning_record_to_str
warnings = self.stats.setdefault("warnings", [])
fslocation = warning_message.filename, warning_message.lineno
message = warning_record_to_str(warning_message)
nodeid = item.nodeid if item is not None else ""
warning_report = WarningReport(
fslocation=fslocation, message=message, nodeid=nodeid
)
warnings.append(warning_report)
def pytest_plugin_registered(self, plugin):
if self.config.option.traceconfig:
msg = "PLUGIN registered: %s" % (plugin,)
@@ -358,12 +375,12 @@ class TerminalReporter(object):
def pytest_runtest_logreport(self, report):
rep = report
res = self.config.hook.pytest_report_teststatus(report=rep)
cat, letter, word = res
category, letter, word = res
if isinstance(word, tuple):
word, markup = word
else:
markup = None
self.stats.setdefault(cat, []).append(rep)
self.stats.setdefault(category, []).append(rep)
self._tests_ran = True
if not letter and not word:
# probably passed setup/teardown
@@ -404,6 +421,12 @@ class TerminalReporter(object):
self.currentfspath = -2
def pytest_runtest_logfinish(self, nodeid):
if self.config.getini("console_output_style") == "count":
num_tests = self._session.testscollected
progress_length = len(" [{}/{}]".format(str(num_tests), str(num_tests)))
else:
progress_length = len(" [100%]")
if self.verbosity <= 0 and self._show_progress_info:
self._progress_nodeids_reported.add(nodeid)
last_item = (
@@ -412,31 +435,43 @@ class TerminalReporter(object):
if last_item:
self._write_progress_information_filling_space()
else:
past_edge = (
self._tw.chars_on_current_line + self._PROGRESS_LENGTH + 1
>= self._screen_width
)
w = self._width_of_current_line
past_edge = w + progress_length + 1 >= self._screen_width
if past_edge:
msg = self._get_progress_information_message()
self._tw.write(msg + "\n", cyan=True)
_PROGRESS_LENGTH = len(" [100%]")
def _get_progress_information_message(self):
if self.config.getoption("capture") == "no":
return ""
collected = self._session.testscollected
if collected:
progress = len(self._progress_nodeids_reported) * 100 // collected
return " [{:3d}%]".format(progress)
return " [100%]"
if self.config.getini("console_output_style") == "count":
if collected:
progress = self._progress_nodeids_reported
counter_format = "{{:{}d}}".format(len(str(collected)))
format_string = " [{}/{{}}]".format(counter_format)
return format_string.format(len(progress), collected)
return " [ {} / {} ]".format(collected, collected)
else:
if collected:
progress = len(self._progress_nodeids_reported) * 100 // collected
return " [{:3d}%]".format(progress)
return " [100%]"
def _write_progress_information_filling_space(self):
msg = self._get_progress_information_message()
fill = " " * (
self._tw.fullwidth - self._tw.chars_on_current_line - len(msg) - 1
)
self.write(fill + msg, cyan=True)
w = self._width_of_current_line
fill = self._tw.fullwidth - w - 1
self.write(msg.rjust(fill), cyan=True)
@property
def _width_of_current_line(self):
"""Return the width of current line, using the superior implementation of py-1.6 when available"""
try:
return self._tw.width_of_current_line
except AttributeError:
# py < 1.6.0
return self._tw.chars_on_current_line
def pytest_collection(self):
if not self.isatty and self.config.option.verbose >= 1:
@@ -685,13 +720,22 @@ class TerminalReporter(object):
self.write_sep("=", "warnings summary", yellow=True, bold=False)
for location, warning_records in grouped:
self._tw.line(str(location) if location else "<undetermined location>")
# legacy warnings show their location explicitly, while standard warnings look better without
# it because the location is already formatted into the message
warning_records = list(warning_records)
is_legacy = warning_records[0].legacy
if location and is_legacy:
self._tw.line(str(location))
for w in warning_records:
lines = w.message.splitlines()
indented = "\n".join(" " + x for x in lines)
self._tw.line(indented)
if is_legacy:
lines = w.message.splitlines()
indented = "\n".join(" " + x for x in lines)
message = indented.rstrip()
else:
message = w.message.rstrip()
self._tw.line(message)
self._tw.line()
self._tw.line("-- Docs: http://doc.pytest.org/en/latest/warnings.html")
self._tw.line("-- Docs: https://docs.pytest.org/en/latest/warnings.html")
def summary_passes(self):
if self.config.option.tbstyle != "no":
@@ -701,12 +745,18 @@ class TerminalReporter(object):
return
self.write_sep("=", "PASSES")
for rep in reports:
msg = self._getfailureheadline(rep)
self.write_sep("_", msg)
self._outrep_summary(rep)
if rep.sections:
msg = self._getfailureheadline(rep)
self.write_sep("_", msg)
self._outrep_summary(rep)
def print_teardown_sections(self, rep):
showcapture = self.config.option.showcapture
if showcapture == "no":
return
for secname, content in rep.sections:
if showcapture != "all" and showcapture not in secname:
continue
if "teardown" in secname:
self._tw.sep("-", secname)
if content[-1:] == "\n":

View File

@@ -9,6 +9,7 @@ import _pytest._code
from _pytest.config import hookimpl
from _pytest.outcomes import fail, skip, xfail
from _pytest.python import transfer_markers, Class, Module, Function
from _pytest.compat import getimfunc
def pytest_pycollect_makeitem(collector, name, obj):
@@ -53,7 +54,7 @@ class UnitTestCase(Class):
x = getattr(self.obj, name)
if not getattr(x, "__test__", True):
continue
funcobj = getattr(x, "im_func", x)
funcobj = getimfunc(x)
transfer_markers(funcobj, cls, module)
yield TestCaseFunction(name, parent=self, callobj=funcobj)
foundsomething = True
@@ -69,6 +70,7 @@ class UnitTestCase(Class):
class TestCaseFunction(Function):
nofuncargs = True
_excinfo = None
_testcase = None
def setup(self):
self._testcase = self.parent.obj(self.name)

View File

@@ -0,0 +1,42 @@
class PytestWarning(UserWarning):
"""
Bases: :class:`UserWarning`.
Base class for all warnings emitted by pytest.
"""
class PytestDeprecationWarning(PytestWarning, DeprecationWarning):
"""
Bases: :class:`pytest.PytestWarning`, :class:`DeprecationWarning`.
Warning class for features that will be removed in a future version.
"""
class RemovedInPytest4Warning(PytestDeprecationWarning):
"""
Bases: :class:`pytest.PytestDeprecationWarning`.
Warning class for features scheduled to be removed in pytest 4.0.
"""
class PytestExperimentalApiWarning(PytestWarning, FutureWarning):
"""
Bases: :class:`pytest.PytestWarning`, :class:`FutureWarning`.
Warning category used to denote experiments in pytest. Use sparingly as the API might change or even be
removed completely in future version
"""
@classmethod
def simple(cls, apiname):
return cls(
"{apiname} is an experimental api that may change over time".format(
apiname=apiname
)
)
PYTESTER_COPY_EXAMPLE = PytestExperimentalApiWarning.simple("testdir.copy_example")

View File

@@ -1,5 +1,6 @@
from __future__ import absolute_import, division, print_function
import sys
import warnings
from contextlib import contextmanager
@@ -49,63 +50,123 @@ def pytest_addoption(parser):
)
def pytest_configure(config):
config.addinivalue_line(
"markers",
"filterwarnings(warning): add a warning filter to the given test. "
"see https://docs.pytest.org/en/latest/warnings.html#pytest-mark-filterwarnings ",
)
@contextmanager
def catch_warnings_for_item(item):
def catch_warnings_for_item(config, ihook, when, item):
"""
catches the warnings generated during setup/call/teardown execution
of the given item and after it is done posts them as warnings to this
item.
Context manager that catches warnings generated in the contained execution block.
``item`` can be None if we are not in the context of an item execution.
Each warning captured triggers the ``pytest_warning_captured`` hook.
"""
args = item.config.getoption("pythonwarnings") or []
inifilters = item.config.getini("filterwarnings")
args = config.getoption("pythonwarnings") or []
inifilters = config.getini("filterwarnings")
with warnings.catch_warnings(record=True) as log:
filters_configured = args or inifilters or sys.warnoptions
for arg in args:
warnings._setoption(arg)
for arg in inifilters:
_setoption(warnings, arg)
for mark in item.iter_markers(name="filterwarnings"):
for arg in mark.args:
warnings._setoption(arg)
if item is not None:
for mark in item.iter_markers(name="filterwarnings"):
for arg in mark.args:
_setoption(warnings, arg)
filters_configured = True
if not filters_configured:
# if user is not explicitly configuring warning filters, show deprecation warnings by default (#2908)
warnings.filterwarnings("always", category=DeprecationWarning)
warnings.filterwarnings("always", category=PendingDeprecationWarning)
yield
for warning in log:
warn_msg = warning.message
unicode_warning = False
if compat._PY2 and any(
isinstance(m, compat.UNICODE_TYPES) for m in warn_msg.args
):
new_args = []
for m in warn_msg.args:
new_args.append(
compat.ascii_escaped(m)
if isinstance(m, compat.UNICODE_TYPES)
else m
)
unicode_warning = list(warn_msg.args) != new_args
warn_msg.args = new_args
msg = warnings.formatwarning(
warn_msg,
warning.category,
warning.filename,
warning.lineno,
warning.line,
for warning_message in log:
ihook.pytest_warning_captured.call_historic(
kwargs=dict(warning_message=warning_message, when=when, item=item)
)
item.warn("unused", msg)
if unicode_warning:
warnings.warn(
"Warning is using unicode non convertible to ascii, "
"converting to a safe representation:\n %s" % msg,
UnicodeWarning,
)
def warning_record_to_str(warning_message):
"""Convert a warnings.WarningMessage to a string, taking in account a lot of unicode shenaningans in Python 2.
When Python 2 support is dropped this function can be greatly simplified.
"""
warn_msg = warning_message.message
unicode_warning = False
if compat._PY2 and any(isinstance(m, compat.UNICODE_TYPES) for m in warn_msg.args):
new_args = []
for m in warn_msg.args:
new_args.append(
compat.ascii_escaped(m) if isinstance(m, compat.UNICODE_TYPES) else m
)
unicode_warning = list(warn_msg.args) != new_args
warn_msg.args = new_args
msg = warnings.formatwarning(
warn_msg,
warning_message.category,
warning_message.filename,
warning_message.lineno,
warning_message.line,
)
if unicode_warning:
warnings.warn(
"Warning is using unicode non convertible to ascii, "
"converting to a safe representation:\n %s" % msg,
UnicodeWarning,
)
return msg
@pytest.hookimpl(hookwrapper=True, tryfirst=True)
def pytest_runtest_protocol(item):
with catch_warnings_for_item(
config=item.config, ihook=item.ihook, when="runtest", item=item
):
yield
@pytest.hookimpl(hookwrapper=True, tryfirst=True)
def pytest_collection(session):
config = session.config
with catch_warnings_for_item(
config=config, ihook=config.hook, when="collect", item=None
):
yield
@pytest.hookimpl(hookwrapper=True)
def pytest_runtest_protocol(item):
with catch_warnings_for_item(item):
def pytest_terminal_summary(terminalreporter):
config = terminalreporter.config
with catch_warnings_for_item(
config=config, ihook=config.hook, when="config", item=None
):
yield
def _issue_config_warning(warning, config):
"""
This function should be used instead of calling ``warnings.warn`` directly when we are in the "configure" stage:
at this point the actual options might not have been set, so we manually trigger the pytest_warning_captured
hook so we can display this warnings in the terminal. This is a hack until we can sort out #2891.
:param warning: the warning instance.
:param config:
"""
with warnings.catch_warnings(record=True) as records:
warnings.simplefilter("always", type(warning))
warnings.warn(warning, stacklevel=2)
config.hook.pytest_warning_captured.call_historic(
kwargs=dict(warning_message=records[0], when="config", item=None)
)

View File

@@ -18,45 +18,55 @@ from _pytest.mark import MARK_GEN as mark, param
from _pytest.main import Session
from _pytest.nodes import Item, Collector, File
from _pytest.fixtures import fillfixtures as _fillfuncargs
from _pytest.python import Module, Class, Instance, Function, Generator
from _pytest.python import Package, Module, Class, Instance, Function, Generator
from _pytest.python_api import approx, raises
from _pytest.warning_types import (
PytestWarning,
PytestDeprecationWarning,
RemovedInPytest4Warning,
PytestExperimentalApiWarning,
)
set_trace = __pytestPDB.set_trace
__all__ = [
"main",
"UsageError",
"cmdline",
"hookspec",
"hookimpl",
"__version__",
"register_assert_rewrite",
"freeze_includes",
"set_trace",
"warns",
"deprecated_call",
"fixture",
"yield_fixture",
"fail",
"skip",
"xfail",
"importorskip",
"exit",
"mark",
"param",
"approx",
"_fillfuncargs",
"Item",
"File",
"Collector",
"Session",
"Module",
"approx",
"Class",
"Instance",
"cmdline",
"Collector",
"deprecated_call",
"exit",
"fail",
"File",
"fixture",
"freeze_includes",
"Function",
"Generator",
"hookimpl",
"hookspec",
"importorskip",
"Instance",
"Item",
"main",
"mark",
"Module",
"Package",
"param",
"PytestDeprecationWarning",
"PytestExperimentalApiWarning",
"PytestWarning",
"raises",
"register_assert_rewrite",
"RemovedInPytest4Warning",
"Session",
"set_trace",
"skip",
"UsageError",
"warns",
"xfail",
"yield_fixture",
]
if __name__ == "__main__":

View File

@@ -2,11 +2,11 @@
from __future__ import absolute_import, division, print_function
import os
import sys
import textwrap
import types
import six
import _pytest._code
import py
import pytest
from _pytest.main import EXIT_NOTESTSCOLLECTED, EXIT_USAGEERROR
@@ -14,13 +14,7 @@ from _pytest.main import EXIT_NOTESTSCOLLECTED, EXIT_USAGEERROR
class TestGeneralUsage(object):
def test_config_error(self, testdir):
testdir.makeconftest(
"""
def pytest_configure(config):
import pytest
raise pytest.UsageError("hello")
"""
)
testdir.copy_example("conftest_usageerror/conftest.py")
result = testdir.runpytest(testdir.tmpdir)
assert result.ret != 0
result.stderr.fnmatch_lines(["*ERROR: hello"])
@@ -137,7 +131,7 @@ class TestGeneralUsage(object):
p2 = testdir.makefile(".pyc", "123")
result = testdir.runpytest(p1, p2)
assert result.ret
result.stderr.fnmatch_lines(["*ERROR: not found:*%s" % (p2.basename,)])
result.stderr.fnmatch_lines(["*ERROR: not found:*{}".format(p2.basename)])
def test_issue486_better_reporting_on_conftest_load_failure(self, testdir):
testdir.makepyfile("")
@@ -170,18 +164,7 @@ class TestGeneralUsage(object):
result.stdout.fnmatch_lines(["*1 skip*"])
def test_issue88_initial_file_multinodes(self, testdir):
testdir.makeconftest(
"""
import pytest
class MyFile(pytest.File):
def collect(self):
return [MyItem("hello", parent=self)]
def pytest_collect_file(path, parent):
return MyFile(path, parent)
class MyItem(pytest.Item):
pass
"""
)
testdir.copy_example("issue88_initial_file_multinodes")
p = testdir.makepyfile("def test_hello(): pass")
result = testdir.runpytest(p, "--collect-only")
result.stdout.fnmatch_lines(["*MyFile*test_issue88*", "*Module*test_issue88*"])
@@ -218,16 +201,16 @@ class TestGeneralUsage(object):
testdir.tmpdir.join("py").mksymlinkto(py._pydir)
p = testdir.tmpdir.join("main.py")
p.write(
_pytest._code.Source(
textwrap.dedent(
"""\
import sys, os
sys.path.insert(0, '')
import py
print(py.__file__)
print(py.__path__)
os.chdir(os.path.dirname(os.getcwd()))
print(py.log)
"""
import sys, os
sys.path.insert(0, '')
import py
print (py.__file__)
print (py.__path__)
os.chdir(os.path.dirname(os.getcwd()))
print (py.log)
"""
)
)
result = testdir.runpython(p)
@@ -470,7 +453,7 @@ class TestInvocationVariants(object):
@pytest.mark.xfail("sys.platform.startswith('java')")
def test_pydoc(self, testdir):
for name in ("py.test", "pytest"):
result = testdir.runpython_c("import %s;help(%s)" % (name, name))
result = testdir.runpython_c("import {};help({})".format(name, name))
assert result.ret == 0
s = result.stdout.str()
assert "MarkGenerator" in s
@@ -594,7 +577,7 @@ class TestInvocationVariants(object):
return what
empty_package = testdir.mkpydir("empty_package")
monkeypatch.setenv("PYTHONPATH", join_pythonpath(empty_package))
monkeypatch.setenv("PYTHONPATH", str(join_pythonpath(empty_package)))
# the path which is not a package raises a warning on pypy;
# no idea why only pypy and not normal python warn about it here
with warnings.catch_warnings():
@@ -603,7 +586,7 @@ class TestInvocationVariants(object):
assert result.ret == 0
result.stdout.fnmatch_lines(["*2 passed*"])
monkeypatch.setenv("PYTHONPATH", join_pythonpath(testdir))
monkeypatch.setenv("PYTHONPATH", str(join_pythonpath(testdir)))
result = testdir.runpytest("--pyargs", "tpkg.test_missing", syspathinsert=True)
assert result.ret != 0
result.stderr.fnmatch_lines(["*not*found*test_missing*"])
@@ -677,6 +660,16 @@ class TestInvocationVariants(object):
["*test_world.py::test_other*PASSED*", "*1 passed*"]
)
def test_invoke_test_and_doctestmodules(self, testdir):
p = testdir.makepyfile(
"""
def test():
pass
"""
)
result = testdir.runpytest(str(p) + "::test", "--doctest-modules")
result.stdout.fnmatch_lines(["*1 passed*"])
@pytest.mark.skipif(not hasattr(os, "symlink"), reason="requires symlinks")
def test_cmdline_python_package_symlink(self, testdir, monkeypatch):
"""
@@ -843,7 +836,7 @@ class TestDurations(object):
if ("test_%s" % x) in line and y in line:
break
else:
raise AssertionError("not found %s %s" % (x, y))
raise AssertionError("not found {} {}".format(x, y))
def test_with_deselected(self, testdir):
testdir.makepyfile(self.source)
@@ -1061,3 +1054,15 @@ def test_frame_leak_on_failing_test(testdir):
)
result = testdir.runpytest_subprocess()
result.stdout.fnmatch_lines(["*1 failed, 1 passed in*"])
def test_fixture_mock_integration(testdir):
"""Test that decorators applied to fixture are left working (#3774)"""
p = testdir.copy_example("acceptance/fixture_mock_integration.py")
result = testdir.runpytest(p)
result.stdout.fnmatch_lines("*1 passed*")
def test_usage_error_code(testdir):
result = testdir.runpytest("-unknown-option-")
assert result.ret == EXIT_USAGEERROR

View File

@@ -1,13 +1,19 @@
# coding: utf-8
from __future__ import absolute_import, division, print_function
import sys
import _pytest._code
import py
import pytest
from test_excinfo import TWMock
from six import text_type
from test_excinfo import TWMock
try:
import mock
except ImportError:
import unittest.mock as mock
def test_ne():
code1 = _pytest._code.Code(compile('foo = "bar"', "", "exec"))
@@ -32,10 +38,8 @@ def test_code_with_class():
pytest.raises(TypeError, "_pytest._code.Code(A)")
if True:
def x():
pass
def x():
raise NotImplementedError()
def test_code_fullsource():
@@ -48,7 +52,7 @@ def test_code_source():
code = _pytest._code.Code(x)
src = code.source()
expected = """def x():
pass"""
raise NotImplementedError()"""
assert str(src) == expected
@@ -68,12 +72,8 @@ def test_getstatement_empty_fullsource():
f = func()
f = _pytest._code.Frame(f)
prop = f.code.__class__.fullsource
try:
f.code.__class__.fullsource = None
assert f.statement == _pytest._code.Source("")
finally:
f.code.__class__.fullsource = prop
with mock.patch.object(f.code.__class__, "fullsource", None):
assert f.statement == ""
def test_code_from_func():
@@ -83,20 +83,20 @@ def test_code_from_func():
def test_unicode_handling():
value = py.builtin._totext("\xc4\x85\xc4\x87\n", "utf-8").encode("utf8")
value = u"ąć".encode("UTF-8")
def f():
raise Exception(value)
excinfo = pytest.raises(Exception, f)
str(excinfo)
if sys.version_info[0] < 3:
text_type(excinfo)
text_type(excinfo)
if sys.version_info < (3,):
bytes(excinfo)
@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")
value = u"ąć".encode("UTF-8")
def f():
raise SyntaxError("invalid syntax", (None, 1, 3, value))
@@ -109,25 +109,25 @@ def test_unicode_handling_syntax_error():
def test_code_getargs():
def f1(x):
pass
raise NotImplementedError()
c1 = _pytest._code.Code(f1)
assert c1.getargs(var=True) == ("x",)
def f2(x, *y):
pass
raise NotImplementedError()
c2 = _pytest._code.Code(f2)
assert c2.getargs(var=True) == ("x", "y")
def f3(x, **z):
pass
raise NotImplementedError()
c3 = _pytest._code.Code(f3)
assert c3.getargs(var=True) == ("x", "z")
def f4(x, *y, **z):
pass
raise NotImplementedError()
c4 = _pytest._code.Code(f4)
assert c4.getargs(var=True) == ("x", "y", "z")
@@ -192,11 +192,14 @@ class TestReprFuncArgs(object):
tw = TWMock()
args = [("unicode_string", u"São Paulo"), ("utf8_string", "S\xc3\xa3o Paulo")]
args = [("unicode_string", u"São Paulo"), ("utf8_string", b"S\xc3\xa3o Paulo")]
r = ReprFuncArgs(args)
r.toterminal(tw)
if sys.version_info[0] >= 3:
assert tw.lines[0] == "unicode_string = São Paulo, utf8_string = São Paulo"
assert (
tw.lines[0]
== r"unicode_string = São Paulo, utf8_string = b'S\xc3\xa3o Paulo'"
)
else:
assert tw.lines[0] == "unicode_string = São Paulo, utf8_string = São Paulo"

View File

@@ -4,9 +4,11 @@ from __future__ import absolute_import, division, print_function
import operator
import os
import sys
import textwrap
import _pytest
import py
import pytest
import six
from _pytest._code.code import (
ExceptionInfo,
FormattedExcinfo,
@@ -147,7 +149,7 @@ class TestTraceback_f_g_h(object):
except somenoname:
pass
xyz()
"""
"""
)
try:
exec(source.compile())
@@ -250,7 +252,7 @@ class TestTraceback_f_g_h(object):
import sys
exc, val, tb = sys.exc_info()
py.builtin._reraise(exc, val, tb)
six.reraise(exc, val, tb)
def f(n):
try:
@@ -268,7 +270,7 @@ class TestTraceback_f_g_h(object):
decorator = pytest.importorskip("decorator").decorator
def log(f, *k, **kw):
print("%s %s" % (k, kw))
print("{} {}".format(k, kw))
f(*k, **kw)
log = decorator(log)
@@ -424,7 +426,7 @@ class TestFormattedExcinfo(object):
@pytest.fixture
def importasmod(self, request):
def importasmod(source):
source = _pytest._code.Source(source)
source = textwrap.dedent(source)
tmpdir = request.getfixturevalue("tmpdir")
modpath = tmpdir.join("mod.py")
tmpdir.ensure("__init__.py")
@@ -448,10 +450,10 @@ class TestFormattedExcinfo(object):
def test_repr_source(self):
pr = FormattedExcinfo()
source = _pytest._code.Source(
"""
"""\
def f(x):
pass
"""
"""
).strip()
pr.flow_marker = "|"
lines = pr.get_source(source, 0)
@@ -579,6 +581,18 @@ raise ValueError()
assert reprlocals.lines[2] == "y = 5"
assert reprlocals.lines[3] == "z = 7"
def test_repr_local_truncated(self):
loc = {"l": [i for i in range(10)]}
p = FormattedExcinfo(showlocals=True)
truncated_reprlocals = p.repr_locals(loc)
assert truncated_reprlocals.lines
assert truncated_reprlocals.lines[0] == "l = [0, 1, 2, 3, 4, 5, ...]"
q = FormattedExcinfo(showlocals=True, truncate_locals=False)
full_reprlocals = q.repr_locals(loc)
assert full_reprlocals.lines
assert full_reprlocals.lines[0] == "l = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]"
def test_repr_tracebackentry_lines(self, importasmod):
mod = importasmod(
"""
@@ -871,10 +885,10 @@ raise ValueError()
class MyRepr(TerminalRepr):
def toterminal(self, tw):
tw.line(py.builtin._totext("я", "utf-8"))
tw.line(u"я")
x = py.builtin._totext(MyRepr())
assert x == py.builtin._totext("я", "utf-8")
x = six.text_type(MyRepr())
assert x == u"я"
def test_toterminal_long(self, importasmod):
mod = importasmod(
@@ -1253,6 +1267,50 @@ raise ValueError()
]
)
@pytest.mark.skipif("sys.version_info[0] < 3")
def test_exc_chain_repr_cycle(self, importasmod):
mod = importasmod(
"""
class Err(Exception):
pass
def fail():
return 0 / 0
def reraise():
try:
fail()
except ZeroDivisionError as e:
raise Err() from e
def unreraise():
try:
reraise()
except Err as e:
raise e.__cause__
"""
)
excinfo = pytest.raises(ZeroDivisionError, mod.unreraise)
r = excinfo.getrepr(style="short")
tw = TWMock()
r.toterminal(tw)
out = "\n".join(line for line in tw.lines if isinstance(line, str))
expected_out = textwrap.dedent(
"""\
:13: in unreraise
reraise()
:10: in reraise
raise Err() from e
E test_exc_chain_repr_cycle0.mod.Err
During handling of the above exception, another exception occurred:
:15: in unreraise
raise e.__cause__
:8: in reraise
fail()
:5: in fail
return 0 / 0
E ZeroDivisionError: division by zero"""
)
assert out == expected_out
@pytest.mark.parametrize("style", ["short", "long"])
@pytest.mark.parametrize("encoding", [None, "utf8", "utf16"])

View File

@@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
# flake8: noqa
# disable flake check on this file because some constructs are strange
# or redundant on purpose and can't be disable on a line-by-line basis
@@ -6,8 +7,8 @@ import inspect
import sys
import _pytest._code
import py
import pytest
import six
from _pytest._code import Source
from _pytest._code.source import ast
@@ -41,15 +42,11 @@ def test_source_str_function():
def test_unicode():
try:
unicode
except NameError:
return
x = Source(unicode("4"))
x = Source(u"4")
assert str(x) == "4"
co = _pytest._code.compile(unicode('u"\xc3\xa5"', "utf8"), mode="eval")
co = _pytest._code.compile(u'u"å"', mode="eval")
val = eval(co)
assert isinstance(val, unicode)
assert isinstance(val, six.text_type)
def test_source_from_function():
@@ -132,7 +129,7 @@ def test_source_strip_multiline():
def test_syntaxerror_rerepresentation():
ex = pytest.raises(SyntaxError, _pytest._code.compile, "xyz xyz")
assert ex.value.lineno == 1
assert ex.value.offset in (4, 7) # XXX pypy/jython versus cpython?
assert ex.value.offset in (4, 5, 7) # XXX pypy/jython versus cpython?
assert ex.value.text.strip(), "x x"
@@ -323,7 +320,7 @@ class TestSourceParsingAndCompiling(object):
def test_compile_and_getsource(self):
co = self.source.compile()
py.builtin.exec_(co, globals())
six.exec_(co, globals())
f(7)
excinfo = pytest.raises(AssertionError, "f(6)")
frame = excinfo.traceback[-1].frame
@@ -392,7 +389,7 @@ def test_getfuncsource_dynamic():
def g(): pass
"""
co = _pytest._code.compile(source)
py.builtin.exec_(co, globals())
six.exec_(co, globals())
assert str(_pytest._code.Source(f)).strip() == "def f():\n raise ValueError"
assert str(_pytest._code.Source(g)).strip() == "def g(): pass"
@@ -632,7 +629,7 @@ def test_issue55():
assert str(s) == ' round_trip("""\n""")'
def XXXtest_multiline():
def test_multiline():
source = getstatement(
0,
"""\

View File

@@ -1,7 +1,11 @@
from __future__ import absolute_import, division, print_function
import os
import pytest
@pytest.mark.filterwarnings("default")
def test_yield_tests_deprecation(testdir):
testdir.makepyfile(
"""
@@ -15,16 +19,18 @@ def test_yield_tests_deprecation(testdir):
yield func1, 1, 1
"""
)
result = testdir.runpytest("-ra")
result = testdir.runpytest()
result.stdout.fnmatch_lines(
[
"*yield tests are deprecated, and scheduled to be removed in pytest 4.0*",
"*test_yield_tests_deprecation.py:3:*yield tests are deprecated*",
"*test_yield_tests_deprecation.py:6:*yield tests are deprecated*",
"*2 passed*",
]
)
assert result.stdout.str().count("yield tests are deprecated") == 2
@pytest.mark.filterwarnings("default")
def test_funcarg_prefix_deprecation(testdir):
testdir.makepyfile(
"""
@@ -39,16 +45,15 @@ def test_funcarg_prefix_deprecation(testdir):
result.stdout.fnmatch_lines(
[
(
"*pytest_funcarg__value: "
'declaring fixtures using "pytest_funcarg__" prefix is deprecated '
"and scheduled to be removed in pytest 4.0. "
"Please remove the prefix and use the @pytest.fixture decorator instead."
"*test_funcarg_prefix_deprecation.py:1: *pytest_funcarg__value: "
'declaring fixtures using "pytest_funcarg__" prefix is deprecated*'
),
"*1 passed*",
]
)
@pytest.mark.filterwarnings("default")
def test_pytest_setup_cfg_deprecated(testdir):
testdir.makefile(
".cfg",
@@ -63,6 +68,7 @@ def test_pytest_setup_cfg_deprecated(testdir):
)
@pytest.mark.filterwarnings("default")
def test_pytest_custom_cfg_deprecated(testdir):
testdir.makefile(
".cfg",
@@ -77,15 +83,15 @@ def test_pytest_custom_cfg_deprecated(testdir):
)
def test_str_args_deprecated(tmpdir, testdir):
def test_str_args_deprecated(tmpdir):
"""Deprecate passing strings to pytest.main(). Scheduled for removal in pytest-4.0."""
from _pytest.main import EXIT_NOTESTSCOLLECTED
warnings = []
class Collect(object):
def pytest_logwarning(self, message):
warnings.append(message)
def pytest_warning_captured(self, warning_message):
warnings.append(str(warning_message.message))
ret = pytest.main("%s -x" % tmpdir, plugins=[Collect()])
msg = (
@@ -100,6 +106,7 @@ def test_getfuncargvalue_is_deprecated(request):
pytest.deprecated_call(request.getfuncargvalue, "tmpdir")
@pytest.mark.filterwarnings("default")
def test_resultlog_is_deprecated(testdir):
result = testdir.runpytest("--help")
result.stdout.fnmatch_lines(["*DEPRECATED path for machine-readable result log*"])
@@ -114,7 +121,7 @@ def test_resultlog_is_deprecated(testdir):
result.stdout.fnmatch_lines(
[
"*--result-log is deprecated and scheduled for removal in pytest 4.0*",
"*See https://docs.pytest.org/*/usage.html#creating-resultlog-format-files for more information*",
"*See https://docs.pytest.org/en/latest/usage.html#creating-resultlog-format-files for more information*",
]
)
@@ -171,21 +178,12 @@ def test_pytest_catchlog_deprecated(testdir, plugin):
def test_pytest_plugins_in_non_top_level_conftest_deprecated(testdir):
from _pytest.deprecated import PYTEST_PLUGINS_FROM_NON_TOP_LEVEL_CONFTEST
subdirectory = testdir.tmpdir.join("subdirectory")
subdirectory.mkdir()
# create the inner conftest with makeconftest and then move it to the subdirectory
testdir.makeconftest(
"""
testdir.makepyfile(
**{
"subdirectory/conftest.py": """
pytest_plugins=['capture']
"""
)
testdir.tmpdir.join("conftest.py").move(subdirectory.join("conftest.py"))
# make the top level conftest
testdir.makeconftest(
"""
import warnings
warnings.filterwarnings('always', category=DeprecationWarning)
"""
}
)
testdir.makepyfile(
"""
@@ -193,13 +191,44 @@ def test_pytest_plugins_in_non_top_level_conftest_deprecated(testdir):
pass
"""
)
res = testdir.runpytest_subprocess()
res = testdir.runpytest()
assert res.ret == 0
res.stderr.fnmatch_lines(
"*" + str(PYTEST_PLUGINS_FROM_NON_TOP_LEVEL_CONFTEST).splitlines()[0]
msg = str(PYTEST_PLUGINS_FROM_NON_TOP_LEVEL_CONFTEST).splitlines()[0]
res.stdout.fnmatch_lines(
"*subdirectory{sep}conftest.py:0: RemovedInPytest4Warning: {msg}*".format(
sep=os.sep, msg=msg
)
)
@pytest.mark.parametrize("use_pyargs", [True, False])
def test_pytest_plugins_in_non_top_level_conftest_deprecated_pyargs(
testdir, use_pyargs
):
"""When using --pyargs, do not emit the warning about non-top-level conftest warnings (#4039, #4044)"""
from _pytest.deprecated import PYTEST_PLUGINS_FROM_NON_TOP_LEVEL_CONFTEST
files = {
"src/pkg/__init__.py": "",
"src/pkg/conftest.py": "",
"src/pkg/test_root.py": "def test(): pass",
"src/pkg/sub/__init__.py": "",
"src/pkg/sub/conftest.py": "pytest_plugins=['capture']",
"src/pkg/sub/test_bar.py": "def test(): pass",
}
testdir.makepyfile(**files)
testdir.syspathinsert(testdir.tmpdir.join("src"))
args = ("--pyargs", "pkg") if use_pyargs else ()
res = testdir.runpytest(*args)
assert res.ret == 0
msg = str(PYTEST_PLUGINS_FROM_NON_TOP_LEVEL_CONFTEST).splitlines()[0]
if use_pyargs:
assert msg not in res.stdout.str()
else:
res.stdout.fnmatch_lines("*{msg}*".format(msg=msg))
def test_pytest_plugins_in_non_top_level_conftest_deprecated_no_top_level_conftest(
testdir
):
@@ -225,8 +254,11 @@ def test_pytest_plugins_in_non_top_level_conftest_deprecated_no_top_level_confte
res = testdir.runpytest_subprocess()
assert res.ret == 0
res.stderr.fnmatch_lines(
"*" + str(PYTEST_PLUGINS_FROM_NON_TOP_LEVEL_CONFTEST).splitlines()[0]
msg = str(PYTEST_PLUGINS_FROM_NON_TOP_LEVEL_CONFTEST).splitlines()[0]
res.stdout.fnmatch_lines(
"*subdirectory{sep}conftest.py:0: RemovedInPytest4Warning: {msg}*".format(
sep=os.sep, msg=msg
)
)
@@ -259,7 +291,36 @@ def test_pytest_plugins_in_non_top_level_conftest_deprecated_no_false_positives(
)
res = testdir.runpytest_subprocess()
assert res.ret == 0
assert (
str(PYTEST_PLUGINS_FROM_NON_TOP_LEVEL_CONFTEST).splitlines()[0]
not in res.stderr.str()
)
msg = str(PYTEST_PLUGINS_FROM_NON_TOP_LEVEL_CONFTEST).splitlines()[0]
assert msg not in res.stdout.str()
def test_call_fixture_function_deprecated():
"""Check if a warning is raised if a fixture function is called directly (#3661)"""
@pytest.fixture
def fix():
return 1
with pytest.deprecated_call():
assert fix() == 1
def test_pycollector_makeitem_is_deprecated():
from _pytest.python import PyCollector
from _pytest.warning_types import RemovedInPytest4Warning
class PyCollectorMock(PyCollector):
"""evil hack"""
def __init__(self):
self.called = False
def _makeitem(self, *k):
"""hack to disable the actual behaviour"""
self.called = True
collector = PyCollectorMock()
with pytest.warns(RemovedInPytest4Warning):
collector.makeitem("foo", "bar")
assert collector.called

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