Commit Graph

98 Commits

Author SHA1 Message Date
Anthony Sottile b238845d0f Fix _is_setup_py for files encoded differently than locale 2020-05-07 13:14:58 -07:00
Daniel Hahler ac3a42bafd
doctest: strip newlines with unexpected exceptions (#6801) 2020-02-24 15:18:08 +01:00
Daniel Hahler f95c7f5803
doctest: handle any OutcomeException (#6669)
Fixes using `pytest.xfail()` and `pytest.importorskip()` in doctests.

Ref: https://github.com/pytest-dev/pytest/issues/310
2020-02-19 13:16:37 +01:00
Nikolay Kondratyev 5e097970df Fix line detection for properties in doctest tests
Co-Authored-By: Daniel Hahler <github@thequod.de>
2019-11-22 23:50:20 +03:00
MarcoGorelli d863c30c74 Fix plurality mismatch for and in pytest terminal summary 2019-10-27 15:16:24 +00:00
Ran Benita 1984c10427 Fix check_untyped_defs errors in doctest
In order to make the LiteralOutputChecker lazy initialization more
amenable to type checking, I changed it to match the scheme already used
in this file to lazy-initialize PytestDoctestRunner.
2019-10-23 14:20:14 +03:00
Bruno Oliveira 47c2091ecd Use new no-match functions to replace previous idiom 2019-10-06 18:05:24 -03:00
David Röthlisberger a740ef2036 docs: Document doctest +NUMBER limitation with strings
Also added an "xfail" testcase for the same.
2019-07-11 10:06:57 +01:00
David Röthlisberger 4c590e002f Fix test_doctest.test_number_non_matches
These doctests were expected to fail, but they were failing because of a
silly bug (I forgot to replace "{expression}" with the actual expression
to be tested), not because of the thing they were meant to be testing.

Then I had to fix one of the testcases because it was actually matching:

    >>> 3.0 #doctest: +NUMBER
    2.99

The doctest is saying that the actual output should match to 2 decimal
places, i.e. within 0.01 -- which it is, so it passes. I changed the
expected output to 2.98 and now it doesn't match (as we expect).
2019-07-11 09:57:44 +01:00
David Röthlisberger aaa7e837cc doctest: Add +NUMBER option to ignore irrelevant floating-point differences
When enabled, floating-point numbers only need to match as far as the
precision you have written in the expected doctest output. This avoids
false positives caused by limited floating-point precision, like this:

    Expected:
        0.233
    Got:
        0.23300000000000001

This is inspired by Sébastien Boisgérault's [numtest] but the
implementation is a bit different:

* This implementation edits the literals that are in the "got"
  string (the actual output from the expression being tested), and then
  proceeds to compare the strings literally. This is similar to pytest's
  existing ALLOW_UNICODE and ALLOW_BYTES implementation.

* This implementation only compares floats against floats, not ints
  against floats. That is, the following doctest will fail with pytest
  whereas it would pass with numtest:

      >>> math.py  # doctest: +NUMBER
      3

  This behaviour should be less surprising (less false negatives) when
  you enable NUMBER globally in pytest.ini.

Advantages of this implementation compared to numtest:

* Doesn't require `import numtest` at the top level of the file.
* Works with pytest (if you try to use pytest & numtest together, pytest
  raises "TypeError: unbound method check_output() must be called with
  NumTestOutputChecker instance as first argument (got
  LiteralsOutputChecker instance instead)").
* Works with Python 3.

[numtest]: https://github.com/boisgera/numtest
2019-07-08 17:07:58 +01:00
Zac-HD c5a549b5bb Emit warning for broken object 2019-06-09 22:17:40 +10:00
Anthony Sottile be2be040f9 Clean up u' prefixes and py2 bytes conversions 2019-06-04 17:50:34 -07:00
Anthony Sottile 4df529e5b9 Clean up __future__ and coding: in tests 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 7573747cda Normalize all source encoding declarations 2019-05-14 19:42:44 -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
Takafumi Arakaki fa3cca51e1 Test pytest.skip in doctest 2019-03-15 11:06:57 +09:00
Ronny Pfannschmidt a6988aa0b9 fix doctest module when a mock object is around
fixes #3456
2019-01-10 12:50:22 +01:00
Anthony Sottile 2368fbb63c Apply reorder-python-imports to all files 2018-10-25 00:01:29 -07:00
Anthony Sottile 85482d575e Replace Source with dedent where possible 2018-08-23 09:06:17 -07:00
Anthony Sottile cbaa7dd56a Upgrade pre-commit hooks except pyupgrade 2018-06-26 06:35:27 -07:00
John T. Wodder II 5221a14764 Failing test case for #3583 2018-06-15 17:23:49 +00:00
Ronny Pfannschmidt 703e4b11ba run black 2018-05-23 16:48:46 +02:00
Ronny Pfannschmidt 9aacb4635e run pyupgrade 2018-05-23 16:45:09 +02:00
William Lee f4cc45bb41 Turn on the continue on failure only when the flag is given 2018-02-23 22:31:11 -06:00
William Lee 7f2dd74ae9 Fixed test for the continue run 2018-02-23 21:20:14 -06:00
William Lee fbc45be83f Fixed #3149 where doctest does not continue to run when there is a failure 2018-02-22 21:00:54 -06:00
Bruno Oliveira f3a119c06a Merge upstream/master into features 2017-11-03 16:37:18 -02:00
je eaf38c7239 call path.read(), add tests, add news fragment 2017-10-14 00:49:54 +08:00
Nguyễn Hồng Quân d40d77432c Add test case for DoctestItem.reportinfo() 2017-07-24 23:07:45 +07:00
Andras Tim 7248b759e8 Fixed E303 flake8 errors
too many blank lines (3)
2017-07-17 01:44:23 +02:00
Andras Tim 195a816522 Fixed E265 flake8 errors
block comment should start with ‘# ‘
2017-07-17 01:44:22 +02:00
Andras Tim 4c24947785 Fixed E241 flake8 errors
multiple spaces after ‘,’
2017-07-17 01:44:22 +02:00
Andras Tim cf97159009 Fixed E128 flake8 errors
continuation line under-indented for visual indent
2017-07-17 01:28:16 +02:00
Andras Tim 6146ac97d9 Fixed E101 flake8 errors
indentation contains mixed spaces and tabs
2017-07-17 01:28:16 +02:00
Andras Tim 6af2abdb53 Fixed flake8 warnings
W191 indentation contains tabs
W292 no newline at end of file
W293 blank line contains whitespace
W391 blank line at end of file
2017-07-17 01:28:16 +02:00
Bruno Oliveira b09d60c60a Fix decode error in Python 2 for doctests in docstrings
Fix #2434
2017-06-13 19:41:34 -03:00
Bruno Oliveira 836dc451f4 Fix unicode issue while running doctests in Python 2
Fix #2434
2017-05-26 07:35:14 -03:00
Bruno Oliveira 42a5d6bdfa Add __future__ imports to all pytest modules
This prevents silly errors from creeping in Python 2 when testing in Python 3
2017-03-16 22:45:40 -03:00
Michal Wajszczuk fb0b90646e New-style classes implemented for python 2.7 - #2147 2017-02-16 20:28:17 +01:00
Bruno Oliveira 402fbe503a Merge branch 'master' into merge-master-into-features 2016-12-27 23:31:26 -02:00
Bruno Oliveira 515fb09995 Move module error compatibility code to _pytest.compat 2016-12-27 22:01:22 -02:00
Miro Hrončok 1680eeb3a3 Tests: Check for ModuleNotFoundError on Python 3.6+
Those tests originally checked for ImportError. Since Python 3.6
ModuleNotFoundError is raised in this context instead, the tests didn't work
as they are text based (so exception inheritance does not save the day).

Fixes https://github.com/pytest-dev/pytest/issues/2132
2016-12-27 23:15:12 +01:00
Manuel Krebber f8fef07b4c Fixed the tests for python 2.6 2016-11-30 14:19:07 +01:00
Manuel Krebber c043bbb854 Changed the doctest_encoding option to an ini option.
Parametrized the tests for it.
2016-11-30 11:43:33 +01:00
Manuel Krebber 929912de29 Changed the tests to pass on python 2 as well. 2016-11-29 14:51:17 +01:00