Commit Graph

115 Commits

Author SHA1 Message Date
Ran Benita 7b6e477e2f
Revert "Deprecate raising unittest.SkipTest to skip tests during collection" (#9710)
This reverts commit 25e657bfc1.

Turns out that this *is* a working unittest feature, which pytest should
support, so undo the deprecation.
2022-02-23 15:59:54 +02:00
Ran Benita d00ca3f8e5 unittest: restore `UnitTestFunction.obj` to return unbound rather than bound method
This fixes #9610.

pytest 7.0.0 (unintentionally) changed `UnitTestFunction.obj`'s' behavior
to match `Function.obj`. That is probably a good thing to have, however
it evidently causes some regressions as described in the issue, so
restore the previous behavior for now. In the future we might want to
make this change again, but with proper consideration.
2022-02-08 00:46:00 +02:00
Miro Hrončok 51293de324 Ignore DeprecationWarnings in test_trial_error
Fixes https://github.com/pytest-dev/pytest/issues/8663
2021-05-12 13:38:19 +02:00
Ran Benita f2d65c85f4 code: export ExceptionInfo for typing purposes
This type is most prominent in `pytest.raises` and we should allow to
refer to it by a public name.

The type is not in a perfectly "exposable" state. In particular:

- The `traceback` property with type `Traceback` which is derived from
  the `py.code` API and exposes a bunch more types transitively. This
  stuff is *not* exported and probably won't be.

- The `getrepr` method which probably should be private.

But they're already used in the wild so no point in just hiding them
now.

The __init__ API is hidden -- the public API for this are the `from_*`
classmethods.
2021-03-13 15:59:44 +02:00
Alexandros Tzannes 19a2f7425d
Merge pull request #8399 from atzannes/master
closes #8394

Generated fixture names for unittest/xunit/nose should start with underscore
2021-03-04 22:45:57 +02:00
Anton 42d5545f42
unittest: cleanup unexpected success handling (#8231)
* unittest: cleanup unexpected success handling

* update comment
2021-01-13 17:02:26 -08:00
antonblr 15156e94c4 tests: Migrate to pytester - final update 2020-12-18 11:02:38 -08:00
Petter Strandmark eda681af2b
Call Python 3.8 doClassCleanups (#8033) 2020-11-19 12:07:15 +02:00
Ran Benita 4c0513bc18 fixtures: deprecate pytest.yield_fixture() 2020-11-07 17:06:40 +02:00
Anthony Sottile 33d119f71a py36+: com2ann 2020-10-05 18:33:17 -07:00
Anthony Sottile 66bd44c13a py36+: pyupgrade: py36+ 2020-10-03 12:46:54 -07:00
Ran Benita 32bb8f3a63 Bump attrs requirement from >=17.4.0 to >=19.2.0
This allows us to remove the `ATTRS_EQ_FIELD` thing which is causing
some annoyance.
2020-09-27 13:17:59 +03:00
Bruno Oliveira 67cb7ef673 Fix test_plain_unittest_does_not_support_async on pypy3
Fix #7624
2020-08-05 15:24:08 -03:00
Bruno Oliveira 44cd8a3a86
Demonstrate that plain unittest does not support async tests (#7607)
Co-authored-by: Ran Benita <ran@unusedvar.com>
2020-08-04 19:37:41 -03:00
Ran Benita b8471aa527 testing: fix some docstring issues
In preparation for enforcing some docstring lints.
2020-08-03 10:10:43 +03:00
Ran Benita 54ad048be7 Enable check_untyped_defs mypy option for testing/ too 2020-06-05 11:34:20 +03:00
Bruno Oliveira 56bf819c2f
Do not call TestCase.tearDown for skipped tests (#7236)
Fix #7215
2020-05-30 14:33:22 -03:00
Bruno Oliveira 82f584b5a9 Fix test_trial_error in test_unittest
This reverts the test to the state before 04f27d4, which introduced the breaking
change about addCleanup not being called properly for failed tests.
2020-05-02 15:26:55 -03:00
Bruno Oliveira 5c2e96c0e6 Fix cleanup functions not being invoked on test failures
Also delay calling tearDown() when --pdb is given, so users still have
access to the instance variables (which are usually cleaned up during tearDown())
when debugging.

Fix #6947
2020-05-02 15:26:55 -03:00
Bruno Oliveira fd2f172258 Let unittest frameworks deal with async functions
Instead of trying to handle unittest-async functions in pytest_pyfunc_call,
let the unittest framework handle them instead.

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

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

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

Fix #7110
Fix #6924
2020-05-01 15:10:28 -03:00
Ronny Pfannschmidt 451aef65ac prepare tests and disable warnings for asyncio unittest cases
shoehorn unittest async results into python test result interpretation

changelog
2020-03-30 21:55:12 +02:00
Ran Benita d33da078a8 Move ExitCode's definition from _pytest.main to _pytest.config
ExitCode is used in several internal modules and hooks and so with type
annotations added, needs to be imported a lot.

_pytest.main, being the entry point, generally sits at the top of the
import tree.

So, it's not great to have ExitCode defined in _pytest.main, because it
will cause a lot of import cycles once type annotations are added (in
fact there is already one, which this change removes).

Move it to _pytest.config instead.

_pytest.main still imports ExitCode, so importing from there still
works, although external users should really be importing from `pytest`.
2020-02-10 23:55:06 +02:00
Bruno Oliveira 41b7b109e9
Merge branch 'features' into unittest-debug 2019-12-03 10:52:53 -03:00
Daniel Hahler 54a954514b re-run black 2019-11-16 18:55:32 +01:00
Daniel Hahler 04f27d4eb4 unittest: do not use TestCase.debug() with `--pdb`
Fixes https://github.com/pytest-dev/pytest/issues/5991
Fixes https://github.com/pytest-dev/pytest/issues/3823

Ref: https://github.com/pytest-dev/pytest-django/issues/772
Ref: https://github.com/pytest-dev/pytest/pull/1890
Ref: https://github.com/pytest-dev/pytest-django/pull/782

- inject wrapped testMethod

- adjust test_trial_error

- add test for `--trace` with unittests
2019-11-10 00:21:51 +01:00
Daniel Hahler 5b88612e5b tests: harden/fix test_trial_error 2019-10-19 09:03:26 +02:00
Bruno Oliveira 47c2091ecd Use new no-match functions to replace previous idiom 2019-10-06 18:05:24 -03:00
Daniel Hahler b5b710b3ae Merge master into features
Several conflicts, mostly due to 2c402f4bd.

Conflicts:
	.pre-commit-config.yaml
	src/_pytest/outcomes.py
	src/_pytest/python_api.py
	tox.ini
2019-08-02 16:52:51 +02:00
Daniel Hahler 401c3d1109 tests: unittest: fix/harden "test_exit_outcome"
Ref: https://github.com/pytest-dev/pytest/pull/5634#pullrequestreview-265565917
2019-07-23 19:35:51 +02:00
Bruno Oliveira 0824789459 Improve test for pytest.exit handling 2019-07-23 08:53:38 -03:00
Daniel Hahler d35d09f82d unittest: handle outcomes.Exit
This is required for pytest to stop when using "quit" in pdb, and should
get honored/handled in general.
2019-07-20 07:11:49 +02:00
Bruno Oliveira 24a66db8d3 Remove support code for unittest 2
Also moved a pytest_runtest_makereport hook implemented in
nose.py, but nowadays makes more sense to be implemented in
unittest.py
2019-07-11 20:11:06 -03:00
Ronny Pfannschmidt 2b92fee1c3 initial conversion of exit codes to enum 2019-06-15 06:48:00 +02:00
Bruno Oliveira 1f8fd421c4 item.obj is again a bound method on TestCase function items
Fix #5390
2019-06-04 20:22:49 -03:00
Anthony Sottile 5dcf85c17e manual: remove dependence on six 2019-06-03 12:08:02 -03:00
Anthony Sottile a91fe1fedd pre-commit run pyupgrade --all-files 2019-06-03 12:08:02 -03:00
Anthony Sottile 3f1ec520fc pre-commit run reorder-python-imports --all-files 2019-06-03 12:08:01 -03:00
Anthony Sottile 5034399d7a pre-commit run fix-encoding-pragma --all-files 2019-06-03 12:08:01 -03:00
Bruno Oliveira 4d49ba6529 Drop Python 2.7 and 3.4 support
* Update setup.py requires and classifiers
* Drop Python 2.7 and 3.4 from CI
* Update docs dropping 2.7 and 3.4 support
* Fix mock imports and remove tests related to pypi's mock module
* Add py27 and 34 support docs to the sidebar
* Remove usage of six from tmpdir
* Remove six.PY* code blocks
* Remove sys.version_info related code
* Cleanup compat
* Remove obsolete safe_str
* Remove obsolete __unicode__ methods
* Remove compat.PY35 and compat.PY36: not really needed anymore
* Remove unused UNICODE_TYPES
* Remove Jython specific code
* Remove some Python 2 references from docs

Related to #5275
2019-06-02 14:39:11 -03:00
Anthony Sottile dc75b6af47 Use fix-encoding-pragma pre-commit hook 2019-05-14 15:56:31 -07:00
Bruno Oliveira f1183c2422 Remove the 'issue' marker from test suite
It doesn't seem to add much value (why would one execute tests
based on that marker?), plus using the docstring for that
encourages one to write a more descriptive message about the test
2019-05-09 19:36:38 -03:00
Daniel Hahler 08f3b02dfc tests: fnmatch_lines: use list
For strings fnmatch_lines converts it into a Source objects, splitted on
newlines.  This is not necessary here, and it is more consistent to use
lists here in the first place.
2019-03-23 11:36:18 +01:00
Bruno Oliveira c3d7340542 Fix setUpClass being called in subclasses that were skipped
Fix #4700
2019-01-31 20:24:11 -02:00
Anthony Sottile b3700f61ba Fix formatting of print() calls 2018-11-22 00:15:14 -08:00
Anthony Sottile 2368fbb63c Apply reorder-python-imports to all files 2018-10-25 00:01:29 -07:00
Bruno Oliveira 212937eb3e Improve error message when TestCase functions use a parametrized fixture
Fix #2535
2018-10-03 19:43:46 -03:00
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
Anthony Sottile cbaa7dd56a Upgrade pre-commit hooks except pyupgrade 2018-06-26 06:35:27 -07:00
Bruno Oliveira 1b16d649f9 Fix formatting of merged files 2018-05-25 18:21:48 -03:00