Skip to content

Commit

Permalink
Merge pull request #571 from nicoddemus/remove-pytest-logwarning
Browse files Browse the repository at this point in the history
Drop features from old pytest versions
  • Loading branch information
nicoddemus authored Aug 5, 2020
2 parents 56a8526 + 047816f commit abc1ae0
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 64 deletions.
5 changes: 0 additions & 5 deletions src/xdist/dsession.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,11 +268,6 @@ def worker_collectreport(self, node, rep):
assert not rep.passed
self._failed_worker_collectreport(node, rep)

def worker_logwarning(self, message, code, nodeid, fslocation):
"""Emitted when a node calls the pytest_logwarning hook."""
kwargs = dict(message=message, code=code, nodeid=nodeid, fslocation=fslocation)
self.config.hook.pytest_logwarning.call_historic(kwargs=kwargs)

def worker_warning_captured(self, warning_message, when, item):
"""Emitted when a node calls the pytest_warning_captured hook (deprecated in 6.0)."""
kwargs = dict(warning_message=warning_message, when=when, item=item)
Expand Down
14 changes: 0 additions & 14 deletions src/xdist/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,20 +125,6 @@ def pytest_collectreport(self, report):
)
self.sendevent("collectreport", data=data)

# the pytest_logwarning hook was deprecated since pytest 4.0
if hasattr(
_pytest.hookspec, "pytest_logwarning"
) and not _pytest.hookspec.pytest_logwarning.pytest_spec.get("warn_on_impl"):

def pytest_logwarning(self, message, code, nodeid, fslocation):
self.sendevent(
"logwarning",
message=message,
code=code,
nodeid=nodeid,
fslocation=str(fslocation),
)

# the pytest_warning_recorded hook was introduced in pytest 6.0
if hasattr(_pytest.hookspec, "pytest_warning_recorded"):

Expand Down
48 changes: 3 additions & 45 deletions testing/acceptance_test.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import os
import re
import textwrap

import py
import pytest
Expand Down Expand Up @@ -114,9 +113,6 @@ def test_fail2():
assert result.ret == 2
result.stdout.fnmatch_lines(["*Interrupted: stopping*1*", "*1 failed*"])

@pytest.mark.xfail(
reason="#527: Python 3.8 failure in pytest where testdir.tmpdir returns an unexpected value"
)
def test_basetemp_in_subprocesses(self, testdir):
p1 = testdir.makepyfile(
"""
Expand Down Expand Up @@ -674,32 +670,6 @@ def test_crash():
result.stdout.fnmatch_lines(["*hello*", "*1 skipped*"])


def test_issue34_pluginloading_in_subprocess(testdir):
import _pytest.hookspec

if not hasattr(_pytest.hookspec, "pytest_namespace"):
pytest.skip("this pytest version no longer supports pytest_namespace()")

testdir.tmpdir.join("plugin123.py").write(
textwrap.dedent(
"""
def pytest_namespace():
return {'sample_variable': 'testing'}
"""
)
)
testdir.makepyfile(
"""
import pytest
def test_hello():
assert pytest.sample_variable == "testing"
"""
)
result = testdir.runpytest_subprocess("-n1", "-p", "plugin123")
assert result.ret == 0
result.stdout.fnmatch_lines(["*1 passed*"])


def test_fixture_scope_caching_issue503(testdir):
p1 = testdir.makepyfile(
"""
Expand Down Expand Up @@ -777,27 +747,15 @@ def test_ok():

class TestWarnings:
@pytest.mark.parametrize("n", ["-n0", "-n1"])
@pytest.mark.parametrize("warn_type", ["pytest", "builtin"])
def test_warnings(self, testdir, n, request, warn_type):
if warn_type == "builtin":
warn_code = """warnings.warn(UserWarning('this is a warning'))"""
elif warn_type == "pytest":
if not hasattr(request.config, "warn"):
pytest.skip("config.warn has been removed in pytest 4.1")
warn_code = """request.config.warn('', 'this is a warning',
fslocation=py.path.local())"""
else:
assert False
def test_warnings(self, testdir, n):
testdir.makepyfile(
"""
import warnings, py, pytest
@pytest.mark.filterwarnings('ignore:config.warn has been deprecated')
def test_func(request):
{warn_code}
""".format(
warn_code=warn_code
)
warnings.warn(UserWarning('this is a warning'))
"""
)
result = testdir.runpytest(n)
result.stdout.fnmatch_lines(["*this is a warning*", "*1 passed, 1 warning*"])
Expand Down

0 comments on commit abc1ae0

Please sign in to comment.