Skip to content

Merge master into features #4338

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 21 commits into from
Nov 8, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
5e0441d
Update pypi.python.org reference to pypi.org
jdufresne Nov 4, 2018
3415244
doc: add lost changelog entry
blueyed Nov 4, 2018
7cb271b
replace byte/unicode helpers in test_capture with python level syntax
RonnyPfannschmidt Nov 4, 2018
4aa3c4f
Merge pull request #4303 from blueyed/fix-changelog
nicoddemus Nov 4, 2018
4bf6a07
Merge pull request #4305 from RonnyPfannschmidt/cleanup-tobytes
asottile Nov 5, 2018
85a3333
Don't string-compare version numbers
asottile Nov 5, 2018
db99633
Merge pull request #4302 from jdufresne/pypi
asottile Nov 5, 2018
a481984
Use unicode/bytes literals instead of calls
asottile Nov 5, 2018
e253852
Merge pull request #4309 from asottile/less_unicode_hax
RonnyPfannschmidt Nov 5, 2018
d42c490
Add missing `-` in front of the new option `--sw`
Lothiraldan Nov 5, 2018
832b59b
Merge pull request #4312 from Lothiraldan/patch-1
nicoddemus Nov 5, 2018
176d274
Merge pull request #4308 from asottile/compare_versions_with_loose_ve…
asottile Nov 5, 2018
fa35f65
Fix handling of duplicate args with regard to Python packages
blueyed Nov 6, 2018
134b103
XXX: revert _collect_seen_pkgdirs
blueyed Nov 7, 2018
f840521
harden test_collect_init_tests
blueyed Nov 7, 2018
f8b944d
pkg_roots
blueyed Nov 7, 2018
bbb9d72
remove paths/parts
blueyed Nov 7, 2018
6fce1f0
pkg_roots per session
blueyed Nov 7, 2018
827573c
cleanup, TODO: use _node_cache
blueyed Nov 7, 2018
64762d2
Merge pull request #4319 from blueyed/harden-test_collect_init_tests
RonnyPfannschmidt Nov 7, 2018
9d838fa
Merge branch 'master' into features
blueyed Nov 8, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Features
existing ``pytest_enter_pdb`` hook.


- `#4147 <https://github.com/pytest-dev/pytest/issues/4147>`_: Add ``-sw``, ``--stepwise`` as an alternative to ``--lf -x`` for stopping at the first failure, but starting the next test invocation from that test. See `the documentation <https://docs.pytest.org/en/latest/cache.html#stepwise>`__ for more info.
- `#4147 <https://github.com/pytest-dev/pytest/issues/4147>`_: Add ``--sw``, ``--stepwise`` as an alternative to ``--lf -x`` for stopping at the first failure, but starting the next test invocation from that test. See `the documentation <https://docs.pytest.org/en/latest/cache.html#stepwise>`__ for more info.


- `#4188 <https://github.com/pytest-dev/pytest/issues/4188>`_: Make ``--color`` emit colorful dots when not running in verbose mode. Earlier, it would only colorize the test-by-test output if ``--verbose`` was also passed.
Expand Down Expand Up @@ -60,6 +60,8 @@ Bug Fixes
- `#611 <https://github.com/pytest-dev/pytest/issues/611>`_: Naming a fixture ``request`` will now raise a warning: the ``request`` fixture is internal and
should not be overwritten as it will lead to internal errors.

- `#4266 <https://github.com/pytest-dev/pytest/issues/4266>`_: Handle (ignore) exceptions raised during collection, e.g. with Django's LazySettings proxy class.



Improved Documentation
Expand Down
1 change: 1 addition & 0 deletions changelog/4305.trivial.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Replace byte/unicode helpers in test_capture with python level syntax.
1 change: 1 addition & 0 deletions changelog/4306.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Parse ``minversion`` as an actual version and not as dot-separated strings.
1 change: 1 addition & 0 deletions changelog/4310.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix duplicate collection due to multiple args matching the same packages.
1 change: 0 additions & 1 deletion doc/4266.bugfix.rst

This file was deleted.

4 changes: 2 additions & 2 deletions doc/en/plugins.rst
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ To see a complete list of all plugins with their latest testing
status against different pytest and Python versions, please visit
`plugincompat <http://plugincompat.herokuapp.com/>`_.

You may also discover more plugins through a `pytest- pypi.python.org search`_.
You may also discover more plugins through a `pytest- pypi.org search`_.

.. _`pytest- pypi.python.org search`: https://pypi.org/search/?q=pytest-
.. _`pytest- pypi.org search`: https://pypi.org/search/?q=pytest-


.. _`available installable plugins`:
Expand Down
76 changes: 34 additions & 42 deletions src/_pytest/assertion/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
import _pytest._code
from ..compat import Sequence

u = six.text_type

# The _reprcompare attribute on the util module is used by the new assertion
# interpretation code and assertion rewriter to detect this plugin was
# loaded and in turn call the hooks defined here as part of the
Expand All @@ -23,9 +21,9 @@
# the re-encoding is needed for python2 repr
# with non-ascii characters (see issue 877 and 1379)
def ecu(s):
try:
return u(s, "utf-8", "replace")
except TypeError:
if isinstance(s, bytes):
return s.decode("UTF-8", "replace")
else:
return s


Expand All @@ -42,7 +40,7 @@ def format_explanation(explanation):
explanation = ecu(explanation)
lines = _split_explanation(explanation)
result = _format_lines(lines)
return u("\n").join(result)
return u"\n".join(result)


def _split_explanation(explanation):
Expand All @@ -52,7 +50,7 @@ def _split_explanation(explanation):
Any other newlines will be escaped and appear in the line as the
literal '\n' characters.
"""
raw_lines = (explanation or u("")).split("\n")
raw_lines = (explanation or u"").split("\n")
lines = [raw_lines[0]]
for values in raw_lines[1:]:
if values and values[0] in ["{", "}", "~", ">"]:
Expand All @@ -77,13 +75,13 @@ def _format_lines(lines):
for line in lines[1:]:
if line.startswith("{"):
if stackcnt[-1]:
s = u("and ")
s = u"and "
else:
s = u("where ")
s = u"where "
stack.append(len(result))
stackcnt[-1] += 1
stackcnt.append(0)
result.append(u(" +") + u(" ") * (len(stack) - 1) + s + line[1:])
result.append(u" +" + u" " * (len(stack) - 1) + s + line[1:])
elif line.startswith("}"):
stack.pop()
stackcnt.pop()
Expand All @@ -92,7 +90,7 @@ def _format_lines(lines):
assert line[0] in ["~", ">"]
stack[-1] += 1
indent = len(stack) if line.startswith("~") else len(stack) - 1
result.append(u(" ") * indent + line[1:])
result.append(u" " * indent + line[1:])
assert len(stack) == 1
return result

Expand All @@ -110,7 +108,7 @@ def assertrepr_compare(config, op, left, right):
left_repr = py.io.saferepr(left, maxsize=int(width // 2))
right_repr = py.io.saferepr(right, maxsize=width - len(left_repr))

summary = u("%s %s %s") % (ecu(left_repr), op, ecu(right_repr))
summary = u"%s %s %s" % (ecu(left_repr), op, ecu(right_repr))

def issequence(x):
return isinstance(x, Sequence) and not isinstance(x, basestring)
Expand Down Expand Up @@ -155,11 +153,9 @@ def isiterable(obj):
explanation = _notin_text(left, right, verbose)
except Exception:
explanation = [
u(
"(pytest_assertion plugin: representation of details failed. "
"Probably an object has a faulty __repr__.)"
),
u(_pytest._code.ExceptionInfo()),
u"(pytest_assertion plugin: representation of details failed. "
u"Probably an object has a faulty __repr__.)",
six.text_type(_pytest._code.ExceptionInfo()),
]

if not explanation:
Expand Down Expand Up @@ -203,8 +199,7 @@ def escape_for_readable_diff(binary_text):
if i > 42:
i -= 10 # Provide some context
explanation = [
u("Skipping %s identical leading characters in diff, use -v to show")
% i
u"Skipping %s identical leading characters in diff, use -v to show" % i
]
left = left[i:]
right = right[i:]
Expand All @@ -215,11 +210,8 @@ def escape_for_readable_diff(binary_text):
if i > 42:
i -= 10 # Provide some context
explanation += [
u(
"Skipping %s identical trailing "
"characters in diff, use -v to show"
)
% i
u"Skipping {} identical trailing "
u"characters in diff, use -v to show".format(i)
]
left = left[:-i]
right = right[:-i]
Expand All @@ -237,21 +229,21 @@ def escape_for_readable_diff(binary_text):

def _compare_eq_iterable(left, right, verbose=False):
if not verbose:
return [u("Use -v to get the full diff")]
return [u"Use -v to get the full diff"]
# dynamic import to speedup pytest
import difflib

try:
left_formatting = pprint.pformat(left).splitlines()
right_formatting = pprint.pformat(right).splitlines()
explanation = [u("Full diff:")]
explanation = [u"Full diff:"]
except Exception:
# hack: PrettyPrinter.pformat() in python 2 fails when formatting items that can't be sorted(), ie, calling
# sorted() on a list would raise. See issue #718.
# As a workaround, the full diff is generated by using the repr() string of each item of each container.
left_formatting = sorted(repr(x) for x in left)
right_formatting = sorted(repr(x) for x in right)
explanation = [u("Full diff (fallback to calling repr on each item):")]
explanation = [u"Full diff (fallback to calling repr on each item):"]
explanation.extend(
line.strip() for line in difflib.ndiff(left_formatting, right_formatting)
)
Expand All @@ -262,16 +254,16 @@ def _compare_eq_sequence(left, right, verbose=False):
explanation = []
for i in range(min(len(left), len(right))):
if left[i] != right[i]:
explanation += [u("At index %s diff: %r != %r") % (i, left[i], right[i])]
explanation += [u"At index %s diff: %r != %r" % (i, left[i], right[i])]
break
if len(left) > len(right):
explanation += [
u("Left contains more items, first extra item: %s")
u"Left contains more items, first extra item: %s"
% py.io.saferepr(left[len(right)])
]
elif len(left) < len(right):
explanation += [
u("Right contains more items, first extra item: %s")
u"Right contains more items, first extra item: %s"
% py.io.saferepr(right[len(left)])
]
return explanation
Expand All @@ -282,11 +274,11 @@ def _compare_eq_set(left, right, verbose=False):
diff_left = left - right
diff_right = right - left
if diff_left:
explanation.append(u("Extra items in the left set:"))
explanation.append(u"Extra items in the left set:")
for item in diff_left:
explanation.append(py.io.saferepr(item))
if diff_right:
explanation.append(u("Extra items in the right set:"))
explanation.append(u"Extra items in the right set:")
for item in diff_right:
explanation.append(py.io.saferepr(item))
return explanation
Expand All @@ -297,26 +289,26 @@ def _compare_eq_dict(left, right, verbose=False):
common = set(left).intersection(set(right))
same = {k: left[k] for k in common if left[k] == right[k]}
if same and verbose < 2:
explanation += [u("Omitting %s identical items, use -vv to show") % len(same)]
explanation += [u"Omitting %s identical items, use -vv to show" % len(same)]
elif same:
explanation += [u("Common items:")]
explanation += [u"Common items:"]
explanation += pprint.pformat(same).splitlines()
diff = {k for k in common if left[k] != right[k]}
if diff:
explanation += [u("Differing items:")]
explanation += [u"Differing items:"]
for k in diff:
explanation += [
py.io.saferepr({k: left[k]}) + " != " + py.io.saferepr({k: right[k]})
]
extra_left = set(left) - set(right)
if extra_left:
explanation.append(u("Left contains more items:"))
explanation.append(u"Left contains more items:")
explanation.extend(
pprint.pformat({k: left[k] for k in extra_left}).splitlines()
)
extra_right = set(right) - set(left)
if extra_right:
explanation.append(u("Right contains more items:"))
explanation.append(u"Right contains more items:")
explanation.extend(
pprint.pformat({k: right[k] for k in extra_right}).splitlines()
)
Expand All @@ -329,14 +321,14 @@ def _notin_text(term, text, verbose=False):
tail = text[index + len(term) :]
correct_text = head + tail
diff = _diff_text(correct_text, text, verbose)
newdiff = [u("%s is contained here:") % py.io.saferepr(term, maxsize=42)]
newdiff = [u"%s is contained here:" % py.io.saferepr(term, maxsize=42)]
for line in diff:
if line.startswith(u("Skipping")):
if line.startswith(u"Skipping"):
continue
if line.startswith(u("- ")):
if line.startswith(u"- "):
continue
if line.startswith(u("+ ")):
newdiff.append(u(" ") + line[2:])
if line.startswith(u"+ "):
newdiff.append(u" " + line[2:])
else:
newdiff.append(line)
return newdiff
4 changes: 2 additions & 2 deletions src/_pytest/capture.py
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ class FDCaptureBinary(object):
snap() produces `bytes`
"""

EMPTY_BUFFER = bytes()
EMPTY_BUFFER = b""

def __init__(self, targetfd, tmpfile=None):
self.targetfd = targetfd
Expand Down Expand Up @@ -630,7 +630,7 @@ def writeorg(self, data):


class SysCaptureBinary(SysCapture):
EMPTY_BUFFER = bytes()
EMPTY_BUFFER = b""

def snap(self):
res = self.tmpfile.buffer.getvalue()
Expand Down
5 changes: 2 additions & 3 deletions src/_pytest/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import sys
import types
import warnings
from distutils.version import LooseVersion

import py
import six
Expand Down Expand Up @@ -817,9 +818,7 @@ def _checkversion(self):

minver = self.inicfg.get("minversion", None)
if minver:
ver = minver.split(".")
myver = pytest.__version__.split(".")
if myver < ver:
if LooseVersion(minver) > LooseVersion(pytest.__version__):
raise pytest.UsageError(
"%s:%d: requires pytest-%s, actual pytest-%s'"
% (
Expand Down
Loading