Skip to content

Commit 69ad202

Browse files
Merge pull request #1 from pytest-dev/master
Update repository
2 parents a7268aa + 9d90093 commit 69ad202

File tree

9 files changed

+87
-10
lines changed

9 files changed

+87
-10
lines changed

CHANGELOG.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ Features
6767
rather than implicitly.
6868

6969

70-
- `#5914 <https://github.com/pytest-dev/pytest/issues/5914>`_: ``pytester`` learned two new functions, `no_fnmatch_line <https://docs.pytest.org/en/latest/reference.html#_pytest.pytester.LineMatcher.no_fnmatch_line>`_ and
70+
- `#5914 <https://github.com/pytest-dev/pytest/issues/5914>`_: `testdir <https://docs.pytest.org/en/latest/reference.html#testdir>`__ learned two new functions, `no_fnmatch_line <https://docs.pytest.org/en/latest/reference.html#_pytest.pytester.LineMatcher.no_fnmatch_line>`_ and
7171
`no_re_match_line <https://docs.pytest.org/en/latest/reference.html#_pytest.pytester.LineMatcher.no_re_match_line>`_.
7272

7373
The functions are used to ensure the captured text *does not* match the given
@@ -77,12 +77,14 @@ Features
7777

7878
.. code-block:: python
7979
80+
result = testdir.runpytest()
8081
assert re.match(pat, result.stdout.str()) is None
8182
8283
Or the ``in`` operator:
8384

8485
.. code-block:: python
8586
87+
result = testdir.runpytest()
8688
assert text in result.stdout.str()
8789
8890
But the new functions produce best output on failure.

changelog/6082.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix line detection for doctest samples inside ``property`` docstrings, as a workaround to `bpo-17446 <https://bugs.python.org/issue17446>`__.

changelog/6254.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix compatibility with pytest-parallel (regression in pytest 5.3.0).

doc/en/reference.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1215,6 +1215,15 @@ passed multiple times. The expected format is ``name=value``. For example::
12151215
a specific entry in the log. ``extra`` kwarg overrides the value specified
12161216
on the command line or in the config.
12171217

1218+
.. confval:: log_cli
1219+
1220+
Enable log display during test run (also known as :ref:`"live logging" <live_logs>`).
1221+
The default is ``False``.
1222+
1223+
.. code-block:: ini
1224+
1225+
[pytest]
1226+
log_cli = True
12181227
12191228
.. confval:: log_cli_date_format
12201229

src/_pytest/config/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -784,7 +784,7 @@ def cwd_relative_nodeid(self, nodeid):
784784

785785
@classmethod
786786
def fromdictargs(cls, option_dict, args):
787-
""" constructor useable for subprocesses. """
787+
""" constructor usable for subprocesses. """
788788
config = get_config(args)
789789
config.option.__dict__.update(option_dict)
790790
config.parse(args, addopts=False)

src/_pytest/doctest.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,16 @@ class MockAwareDocTestFinder(doctest.DocTestFinder):
435435
https://bugs.python.org/issue25532
436436
"""
437437

438+
def _find_lineno(self, obj, source_lines):
439+
"""
440+
Doctest code does not take into account `@property`, this is a hackish way to fix it.
441+
442+
https://bugs.python.org/issue17446
443+
"""
444+
if isinstance(obj, property):
445+
obj = getattr(obj, "fget", obj)
446+
return doctest.DocTestFinder._find_lineno(self, obj, source_lines)
447+
438448
def _find(self, tests, obj, name, module, source_lines, globs, seen):
439449
if _is_mocked(obj):
440450
return

src/_pytest/terminal.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1099,7 +1099,7 @@ def _get_main_color(stats) -> Tuple[str, List[str]]:
10991099
"failed passed skipped deselected xfailed xpassed warnings error".split()
11001100
)
11011101
unknown_type_seen = False
1102-
for found_type in stats:
1102+
for found_type in stats.keys():
11031103
if found_type not in known_types:
11041104
if found_type: # setup/teardown reports have an empty key, ignore them
11051105
known_types.append(found_type)

testing/test_doctest.py

Lines changed: 60 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -287,13 +287,68 @@ def test(self):
287287
)
288288
)
289289
result = testdir.runpytest("--doctest-modules")
290+
result.stdout.fnmatch_lines(
291+
["*hello*", "006*>>> 1/0*", "*UNEXPECTED*ZeroDivision*", "*1 failed*"]
292+
)
293+
294+
def test_doctest_linedata_on_property(self, testdir):
295+
testdir.makepyfile(
296+
"""
297+
class Sample(object):
298+
@property
299+
def some_property(self):
300+
'''
301+
>>> Sample().some_property
302+
'another thing'
303+
'''
304+
return 'something'
305+
"""
306+
)
307+
result = testdir.runpytest("--doctest-modules")
290308
result.stdout.fnmatch_lines(
291309
[
292-
"*hello*",
293-
"*EXAMPLE LOCATION UNKNOWN, not showing all tests of that example*",
294-
"*1/0*",
295-
"*UNEXPECTED*ZeroDivision*",
296-
"*1 failed*",
310+
"*= FAILURES =*",
311+
"*_ [[]doctest[]] test_doctest_linedata_on_property.Sample.some_property _*",
312+
"004 ",
313+
"005 >>> Sample().some_property",
314+
"Expected:",
315+
" 'another thing'",
316+
"Got:",
317+
" 'something'",
318+
"",
319+
"*/test_doctest_linedata_on_property.py:5: DocTestFailure",
320+
"*= 1 failed in *",
321+
]
322+
)
323+
324+
def test_doctest_no_linedata_on_overriden_property(self, testdir):
325+
testdir.makepyfile(
326+
"""
327+
class Sample(object):
328+
@property
329+
def some_property(self):
330+
'''
331+
>>> Sample().some_property
332+
'another thing'
333+
'''
334+
return 'something'
335+
some_property = property(some_property.__get__, None, None, some_property.__doc__)
336+
"""
337+
)
338+
result = testdir.runpytest("--doctest-modules")
339+
result.stdout.fnmatch_lines(
340+
[
341+
"*= FAILURES =*",
342+
"*_ [[]doctest[]] test_doctest_no_linedata_on_overriden_property.Sample.some_property _*",
343+
"EXAMPLE LOCATION UNKNOWN, not showing all tests of that example",
344+
"[?][?][?] >>> Sample().some_property",
345+
"Expected:",
346+
" 'another thing'",
347+
"Got:",
348+
" 'something'",
349+
"",
350+
"*/test_doctest_no_linedata_on_overriden_property.py:None: DocTestFailure",
351+
"*= 1 failed in *",
297352
]
298353
)
299354

tox.ini

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,8 @@ basepython = python3
6060
usedevelop = True
6161
changedir = doc/en
6262
deps = -r{toxinidir}/doc/en/requirements.txt
63-
6463
commands =
65-
sphinx-build -W -b html . _build
64+
sphinx-build -W --keep-going -b html . _build {posargs:}
6665

6766
[testenv:docs-checklinks]
6867
basepython = python3

0 commit comments

Comments
 (0)