Skip to content

Commit

Permalink
Revert "Merge master into features (pytest-dev#5874)"
Browse files Browse the repository at this point in the history
This reverts commit c28b631, reversing
changes made to 7c64d5d.
  • Loading branch information
nicoddemus committed Sep 23, 2019
1 parent c28b631 commit 44800c4
Show file tree
Hide file tree
Showing 27 changed files with 119 additions and 530 deletions.
1 change: 0 additions & 1 deletion AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,6 @@ mbyt
Michael Aquilina
Michael Birtwell
Michael Droettboom
Michael Goerz
Michael Seifert
Michal Wajszczuk
Mihai Capotă
Expand Down
2 changes: 0 additions & 2 deletions changelog/1682.deprecation.rst

This file was deleted.

3 changes: 0 additions & 3 deletions changelog/1682.feature.rst

This file was deleted.

1 change: 0 additions & 1 deletion changelog/5056.trivial.rst

This file was deleted.

1 change: 0 additions & 1 deletion changelog/5764.feature.rst

This file was deleted.

1 change: 0 additions & 1 deletion changelog/5806.bugfix.rst

This file was deleted.

2 changes: 1 addition & 1 deletion doc/en/example/costlysetup/conftest.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import pytest


@pytest.fixture(scope="session")
@pytest.fixture("session")
def setup(request):
setup = CostlySetup()
yield setup
Expand Down
26 changes: 0 additions & 26 deletions doc/en/fixture.rst
Original file line number Diff line number Diff line change
Expand Up @@ -301,32 +301,6 @@ are finalized when the last test of a *package* finishes.
Use this new feature sparingly and please make sure to report any issues you find.


Dynamic scope
^^^^^^^^^^^^^

In some cases, you might want to change the scope of the fixture without changing the code.
To do that, pass a callable to ``scope``. The callable must return a string with a valid scope
and will be executed only once - during the fixture definition. It will be called with two
keyword arguments - ``fixture_name`` as a string and ``config`` with a configuration object.

This can be especially useful when dealing with fixtures that need time for setup, like spawning
a docker container. You can use the command-line argument to control the scope of the spawned
containers for different environments. See the example below.

.. code-block:: python
def determine_scope(fixture_name, config):
if config.getoption("--keep-containers"):
return "session"
return "function"
@pytest.fixture(scope=determine_scope)
def docker_container():
yield spawn_container()
Order: Higher-scoped fixtures are instantiated first
----------------------------------------------------

Expand Down
27 changes: 10 additions & 17 deletions src/_pytest/_code/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,10 @@
from inspect import CO_VARARGS
from inspect import CO_VARKEYWORDS
from traceback import format_exception_only
from types import CodeType
from types import TracebackType
from typing import Any
from typing import Dict
from typing import Generic
from typing import List
from typing import Optional
from typing import Pattern
from typing import Set
from typing import Tuple
from typing import TypeVar
from typing import Union
Expand All @@ -34,7 +29,7 @@
class Code:
""" wrapper around Python code objects """

def __init__(self, rawcode) -> None:
def __init__(self, rawcode):
if not hasattr(rawcode, "co_filename"):
rawcode = getrawcode(rawcode)
try:
Expand All @@ -43,7 +38,7 @@ def __init__(self, rawcode) -> None:
self.name = rawcode.co_name
except AttributeError:
raise TypeError("not a code object: {!r}".format(rawcode))
self.raw = rawcode # type: CodeType
self.raw = rawcode

def __eq__(self, other):
return self.raw == other.raw
Expand Down Expand Up @@ -356,7 +351,7 @@ def recursionindex(self):
""" return the index of the frame/TracebackEntry where recursion
originates if appropriate, None if no recursion occurred
"""
cache = {} # type: Dict[Tuple[Any, int, int], List[Dict[str, Any]]]
cache = {}
for i, entry in enumerate(self):
# id for the code.raw is needed to work around
# the strange metaprogramming in the decorator lib from pypi
Expand Down Expand Up @@ -655,7 +650,7 @@ def repr_args(self, entry):
args.append((argname, saferepr(argvalue)))
return ReprFuncArgs(args)

def get_source(self, source, line_index=-1, excinfo=None, short=False) -> List[str]:
def get_source(self, source, line_index=-1, excinfo=None, short=False):
""" return formatted and marked up source lines. """
import _pytest._code

Expand Down Expand Up @@ -727,7 +722,7 @@ def repr_traceback_entry(self, entry, excinfo=None):
else:
line_index = entry.lineno - entry.getfirstlinesource()

lines = [] # type: List[str]
lines = []
style = entry._repr_style
if style is None:
style = self.style
Expand Down Expand Up @@ -804,7 +799,7 @@ def _truncate_recursive_traceback(self, traceback):
exc_msg=str(e),
max_frames=max_frames,
total=len(traceback),
) # type: Optional[str]
)
traceback = traceback[:max_frames] + traceback[-max_frames:]
else:
if recursionindex is not None:
Expand All @@ -817,12 +812,10 @@ def _truncate_recursive_traceback(self, traceback):

def repr_excinfo(self, excinfo):

repr_chain = (
[]
) # type: List[Tuple[ReprTraceback, Optional[ReprFileLocation], Optional[str]]]
repr_chain = []
e = excinfo.value
descr = None
seen = set() # type: Set[int]
seen = set()
while e is not None and id(e) not in seen:
seen.add(id(e))
if excinfo:
Expand Down Expand Up @@ -875,8 +868,8 @@ def __repr__(self):


class ExceptionRepr(TerminalRepr):
def __init__(self) -> None:
self.sections = [] # type: List[Tuple[str, str, str]]
def __init__(self):
self.sections = []

def addsection(self, name, content, sep="-"):
self.sections.append((name, content, sep))
Expand Down
13 changes: 6 additions & 7 deletions src/_pytest/_code/source.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import warnings
from ast import PyCF_ONLY_AST as _AST_FLAG
from bisect import bisect_right
from typing import List

import py

Expand All @@ -20,11 +19,11 @@ class Source:
_compilecounter = 0

def __init__(self, *parts, **kwargs):
self.lines = lines = [] # type: List[str]
self.lines = lines = []
de = kwargs.get("deindent", True)
for part in parts:
if not part:
partlines = [] # type: List[str]
partlines = []
elif isinstance(part, Source):
partlines = part.lines
elif isinstance(part, (tuple, list)):
Expand Down Expand Up @@ -158,7 +157,8 @@ def compile(
source = "\n".join(self.lines) + "\n"
try:
co = compile(source, filename, mode, flag)
except SyntaxError as ex:
except SyntaxError:
ex = sys.exc_info()[1]
# re-represent syntax errors from parsing python strings
msglines = self.lines[: ex.lineno]
if ex.offset:
Expand All @@ -173,8 +173,7 @@ def compile(
if flag & _AST_FLAG:
return co
lines = [(x + "\n") for x in self.lines]
# Type ignored because linecache.cache is private.
linecache.cache[filename] = (1, None, lines, filename) # type: ignore
linecache.cache[filename] = (1, None, lines, filename)
return co


Expand Down Expand Up @@ -283,7 +282,7 @@ def get_statement_startend2(lineno, node):
return start, end


def getstatementrange_ast(lineno, source: Source, assertion=False, astnode=None):
def getstatementrange_ast(lineno, source, assertion=False, astnode=None):
if astnode is None:
content = str(source)
# See #4260:
Expand Down
11 changes: 3 additions & 8 deletions src/_pytest/assertion/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
support for presenting detailed information in failing assertions.
"""
import sys
from typing import Optional

from _pytest.assertion import rewrite
from _pytest.assertion import truncate
Expand Down Expand Up @@ -53,9 +52,7 @@ def register_assert_rewrite(*names):
importhook = hook
break
else:
# TODO(typing): Add a protocol for mark_rewrite() and use it
# for importhook and for PytestPluginManager.rewrite_hook.
importhook = DummyRewriteHook() # type: ignore
importhook = DummyRewriteHook()
importhook.mark_rewrite(*names)


Expand All @@ -72,7 +69,7 @@ class AssertionState:
def __init__(self, config, mode):
self.mode = mode
self.trace = config.trace.root.get("assertion")
self.hook = None # type: Optional[rewrite.AssertionRewritingHook]
self.hook = None


def install_importhook(config):
Expand Down Expand Up @@ -111,7 +108,6 @@ def pytest_runtest_setup(item):
"""

def callbinrepr(op, left, right):
# type: (str, object, object) -> Optional[str]
"""Call the pytest_assertrepr_compare hook and prepare the result
This uses the first result from the hook and then ensures the
Expand All @@ -137,13 +133,12 @@ def callbinrepr(op, left, right):
if item.config.getvalue("assertmode") == "rewrite":
res = res.replace("%", "%%")
return res
return None

util._reprcompare = callbinrepr

if item.ihook.pytest_assertion_pass.get_hookimpls():

def call_assertion_pass_hook(lineno, orig, expl):
def call_assertion_pass_hook(lineno, expl, orig):
item.ihook.pytest_assertion_pass(
item=item, lineno=lineno, orig=orig, expl=expl
)
Expand Down
Loading

0 comments on commit 44800c4

Please sign in to comment.