Skip to content

WIP: fix #4507 and ensure our modules have no warnings for general import #4510

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

Closed
wants to merge 22 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
9342778
fix #4507 and ensure our modules have no warnigns for general import
RonnyPfannschmidt Dec 5, 2018
ae3e529
add missed file
RonnyPfannschmidt Dec 5, 2018
4621e28
CHANGELOG
RonnyPfannschmidt Dec 5, 2018
892e10b
fix references used in pytester
RonnyPfannschmidt Dec 5, 2018
b17ad82
add some specific warning filters for false positives
RonnyPfannschmidt Dec 5, 2018
9dd0cf6
merge master
RonnyPfannschmidt Jan 23, 2019
1698166
fix merge misstake, return record_xml_attribute
RonnyPfannschmidt Jan 23, 2019
edfcabf
silence lsof and account for virtualenv bug
RonnyPfannschmidt Jan 24, 2019
2b07077
assertion only warns about imp on python3
RonnyPfannschmidt Jan 25, 2019
51b40a3
fix virtualenv version
RonnyPfannschmidt Jan 30, 2019
e1e3e35
fix #4507 and ensure our modules have no warnigns for general import
RonnyPfannschmidt Dec 5, 2018
19fdbee
fix references used in pytester
RonnyPfannschmidt Dec 5, 2018
0eb6b87
add some specific warning filters for false positives
RonnyPfannschmidt Dec 5, 2018
12f85a2
fix merge misstake, return record_xml_attribute
RonnyPfannschmidt Jan 23, 2019
388357d
silence lsof and account for virtualenv bug
RonnyPfannschmidt Jan 24, 2019
61ef3e6
assertion only warns about imp on python3
RonnyPfannschmidt Jan 25, 2019
765a476
commit broken merge in prep for more
RonnyPfannschmidt Aug 8, 2019
ea162a9
Merge branch 'master' into fix-4507
RonnyPfannschmidt Aug 8, 2019
5113afb
more code updates
RonnyPfannschmidt Aug 8, 2019
d96d573
sync junitxml with master
RonnyPfannschmidt Aug 8, 2019
bb706aa
assertion no longer uses imp
RonnyPfannschmidt Aug 8, 2019
2d1d313
type annotate KNOWN BAD
RonnyPfannschmidt Aug 8, 2019
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
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ stages:
python: '3.7'
cache: false

- pip install --upgrade virtualenv>=16.3.0
env:
global:
- PYTEST_ADDOPTS=-vv
Expand Down
1 change: 1 addition & 0 deletions changelog/4507.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Sort out warnings we get at the import time of the internal modules.
10 changes: 6 additions & 4 deletions src/_pytest/cacheprovider.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
import attr
import py

import pytest
from .config import hookimpl
from .fixtures import fixture
from .nodes import Item
from .pathlib import Path
from .pathlib import resolve_from_str
from .pathlib import rm_rf
Expand Down Expand Up @@ -276,7 +278,7 @@ def pytest_collection_modifyitems(self, session, config, items):
items[:] = self._get_increasing_order(
new_items.values()
) + self._get_increasing_order(other_items.values())
self.cached_nodeids = [x.nodeid for x in items if isinstance(x, pytest.Item)]
self.cached_nodeids = [x.nodeid for x in items if isinstance(x, Item)]

def _get_increasing_order(self, items):
return sorted(items, key=lambda item: item.fspath.mtime(), reverse=True)
Expand Down Expand Up @@ -354,14 +356,14 @@ def pytest_cmdline_main(config):
return wrap_session(config, cacheshow)


@pytest.hookimpl(tryfirst=True)
@hookimpl(tryfirst=True)
def pytest_configure(config):
config.cache = Cache.for_config(config)
config.pluginmanager.register(LFPlugin(config), "lfplugin")
config.pluginmanager.register(NFPlugin(config), "nfplugin")


@pytest.fixture
@fixture
def cache(request):
"""
Return a cache object that can persist state between testing sessions.
Expand Down
35 changes: 19 additions & 16 deletions src/_pytest/capture.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@
from io import UnsupportedOperation
from tempfile import TemporaryFile

import pytest
from .config import hookimpl
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

curious why the imports changed, maybe I missed this

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removes the import cycle to pytest

Else we can't import parts of pytest without breaking

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you show me what you mean -- like stacktrace or reproduction or whatnot, I'm not sure I understand (and I don't understand why it's necessary for this PR)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pytest imports from all over the place this preveting isolation, if everything triggers every import then I can't let it effectively tell me what is going on

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Last stack trace I had if this disappeared a few months ago in a terminal, perhaps I could recreate it when I'm back on that computer

from .fixtures import fixture
from .nodes import File
from .outcomes import skip
from _pytest.compat import CaptureIO

patchsysdict = {0: "stdin", 1: "stdout", 2: "stderr"}
Expand All @@ -35,7 +38,7 @@ def pytest_addoption(parser):
)


@pytest.hookimpl(hookwrapper=True)
@hookimpl(hookwrapper=True)
def pytest_load_initial_conftests(early_config, parser, args):
ns = early_config.known_args_namespace
if ns.capture == "fd":
Expand Down Expand Up @@ -193,9 +196,9 @@ def item_capture(self, when, item):

# Hooks

@pytest.hookimpl(hookwrapper=True)
@hookimpl(hookwrapper=True)
def pytest_make_collect_report(self, collector):
if isinstance(collector, pytest.File):
if isinstance(collector, File):
self.resume_global_capture()
outcome = yield
self.suspend_global_capture()
Expand All @@ -208,32 +211,32 @@ def pytest_make_collect_report(self, collector):
else:
yield

@pytest.hookimpl(hookwrapper=True)
@hookimpl(hookwrapper=True)
def pytest_runtest_protocol(self, item):
self._current_item = item
yield
self._current_item = None

@pytest.hookimpl(hookwrapper=True)
@hookimpl(hookwrapper=True)
def pytest_runtest_setup(self, item):
with self.item_capture("setup", item):
yield

@pytest.hookimpl(hookwrapper=True)
@hookimpl(hookwrapper=True)
def pytest_runtest_call(self, item):
with self.item_capture("call", item):
yield

@pytest.hookimpl(hookwrapper=True)
@hookimpl(hookwrapper=True)
def pytest_runtest_teardown(self, item):
with self.item_capture("teardown", item):
yield

@pytest.hookimpl(tryfirst=True)
@hookimpl(tryfirst=True)
def pytest_keyboard_interrupt(self, excinfo):
self.stop_global_capturing()

@pytest.hookimpl(tryfirst=True)
@hookimpl(tryfirst=True)
def pytest_internalerror(self, excinfo):
self.stop_global_capturing()

Expand All @@ -251,7 +254,7 @@ def _ensure_only_one_capture_fixture(request, name):
)


@pytest.fixture
@fixture
def capsys(request):
"""Enable text capturing of writes to ``sys.stdout`` and ``sys.stderr``.

Expand All @@ -264,7 +267,7 @@ def capsys(request):
yield fixture


@pytest.fixture
@fixture
def capsysbinary(request):
"""Enable bytes capturing of writes to ``sys.stdout`` and ``sys.stderr``.

Expand All @@ -277,7 +280,7 @@ def capsysbinary(request):
yield fixture


@pytest.fixture
@fixture
def capfd(request):
"""Enable text capturing of writes to file descriptors ``1`` and ``2``.

Expand All @@ -287,14 +290,14 @@ def capfd(request):
"""
_ensure_only_one_capture_fixture(request, "capfd")
if not hasattr(os, "dup"):
pytest.skip(
skip(
"capfd fixture needs os.dup function which is not available in this system"
)
with _install_capture_fixture_on_item(request, FDCapture) as fixture:
yield fixture


@pytest.fixture
@fixture
def capfdbinary(request):
"""Enable bytes capturing of writes to file descriptors ``1`` and ``2``.

Expand All @@ -304,7 +307,7 @@ def capfdbinary(request):
"""
_ensure_only_one_capture_fixture(request, "capfdbinary")
if not hasattr(os, "dup"):
pytest.skip(
skip(
"capfdbinary fixture needs os.dup function which is not available in this system"
)
with _install_capture_fixture_on_item(request, FDCaptureBinary) as fixture:
Expand Down
5 changes: 3 additions & 2 deletions src/_pytest/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
from pluggy import PluginManager

import _pytest._code
import _pytest.assertion
import _pytest.hookspec # the extension point definitions
from .exceptions import PrintHelp
from .exceptions import UsageError
Expand Down Expand Up @@ -238,7 +237,9 @@ def __init__(self):
self.enable_tracing()

# Config._consider_importhook will set a real object if required.
self.rewrite_hook = _pytest.assertion.DummyRewriteHook()
from _pytest.assertion import DummyRewriteHook

self.rewrite_hook = DummyRewriteHook()
# Used to know when we are importing conftests after the pytest_configure stage
self._configured = False

Expand Down
17 changes: 10 additions & 7 deletions src/_pytest/doctest.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@
import warnings
from contextlib import contextmanager

import pytest
from _pytest._code.code import ExceptionInfo
from _pytest._code.code import ReprFileLocation
from _pytest._code.code import TerminalRepr
from _pytest.compat import safe_getattr
from _pytest.fixtures import fixture
from _pytest.fixtures import FixtureRequest
from _pytest.nodes import Item
from _pytest.outcomes import skip
from _pytest.outcomes import Skipped
from _pytest.python import Module
from _pytest.warning_types import PytestWarning

DOCTEST_REPORT_CHOICE_NONE = "none"
Expand Down Expand Up @@ -176,7 +179,7 @@ def _get_runner(checker=None, verbose=None, optionflags=0, continue_on_failure=T
)


class DoctestItem(pytest.Item):
class DoctestItem(Item):
def __init__(self, name, parent, runner=None, dtest=None):
super().__init__(name, parent)
self.runner = runner
Expand Down Expand Up @@ -308,7 +311,7 @@ def _get_continue_on_failure(config):
return continue_on_failure


class DoctestTextfile(pytest.Module):
class DoctestTextfile(Module):
obj = None

def collect(self):
Expand Down Expand Up @@ -345,7 +348,7 @@ def _check_all_skipped(test):

all_skipped = all(x.options.get(doctest.SKIP, False) for x in test.examples)
if all_skipped:
pytest.skip("all tests skipped by +SKIP option")
skip("all tests skipped by +SKIP option")


def _is_mocked(obj):
Expand Down Expand Up @@ -387,7 +390,7 @@ def _mock_aware_unwrap(obj, stop=None):
inspect.unwrap = real_unwrap


class DoctestModule(pytest.Module):
class DoctestModule(Module):
def collect(self):
import doctest

Expand Down Expand Up @@ -415,7 +418,7 @@ def _find(self, tests, obj, name, module, source_lines, globs, seen):
module = self.fspath.pyimport()
except ImportError:
if self.config.getvalue("doctest_ignore_import_errors"):
pytest.skip("unable to import module %r" % self.fspath)
skip("unable to import module %r" % self.fspath)
else:
raise
# uses internal doctest module parsing mechanism
Expand Down Expand Up @@ -540,7 +543,7 @@ def _get_report_choice(key):
}[key]


@pytest.fixture(scope="session")
@fixture(scope="session")
def doctest_namespace():
"""
Fixture that returns a :py:class:`dict` that will be injected into the namespace of doctests.
Expand Down
10 changes: 8 additions & 2 deletions src/_pytest/helpconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import py

import pytest
from _pytest.config import hookimpl
from _pytest.config import PrintHelp


Expand Down Expand Up @@ -83,11 +83,13 @@ def pytest_addoption(parser):
)


@pytest.hookimpl(hookwrapper=True)
@hookimpl(hookwrapper=True)
def pytest_cmdline_parse():
outcome = yield
config = outcome.get_result()
if config.option.debug:
import pytest

path = os.path.abspath("pytestdebug.log")
debugfile = open(path, "w")
debugfile.write(
Expand Down Expand Up @@ -115,6 +117,8 @@ def unset_tracing():


def showversion(config):
import pytest

p = py.path.local(pytest.__file__)
sys.stderr.write(
"This is pytest version {}, imported from {}\n".format(pytest.__version__, p)
Expand Down Expand Up @@ -223,6 +227,8 @@ def getpluginversioninfo(config):

def pytest_report_header(config):
lines = []
import pytest

if config.option.debug or config.option.traceconfig:
lines.append(
"using: pytest-{} pylib-{}".format(pytest.__version__, py.__version__)
Expand Down
8 changes: 4 additions & 4 deletions src/_pytest/junitxml.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@

import py

import pytest
from _pytest import nodes
from _pytest.config import filename_arg
from _pytest.fixtures import fixture


class Junit(py.xml.Namespace):
Expand Down Expand Up @@ -290,7 +290,7 @@ def _warn_incompatibility_with_xunit2(request, fixture_name):
)


@pytest.fixture
@fixture
def record_property(request):
"""Add an extra properties the calling test.
User properties become part of the test report and are available to the
Expand All @@ -311,7 +311,7 @@ def append_property(name, value):
return append_property


@pytest.fixture
@fixture
def record_xml_attribute(request):
"""Add extra xml attributes to the tag for the calling test.
The fixture is callable with ``(name, value)``, with value being
Expand Down Expand Up @@ -348,7 +348,7 @@ def _check_record_param_type(param, v):
raise TypeError(msg.format(param=param, g=type(v).__name__))


@pytest.fixture(scope="session")
@fixture(scope="session")
def record_testsuite_property(request):
"""
Records a new ``<property>`` tag as child of the root ``<testsuite>``. This is suitable to
Expand Down
Loading