Merge remote-tracking branch 'upstream/master' into merge-master-into-features
This commit is contained in:
@@ -577,7 +577,7 @@ class TestInvocationVariants(object):
|
||||
return what
|
||||
|
||||
empty_package = testdir.mkpydir("empty_package")
|
||||
monkeypatch.setenv("PYTHONPATH", join_pythonpath(empty_package))
|
||||
monkeypatch.setenv("PYTHONPATH", str(join_pythonpath(empty_package)))
|
||||
# the path which is not a package raises a warning on pypy;
|
||||
# no idea why only pypy and not normal python warn about it here
|
||||
with warnings.catch_warnings():
|
||||
@@ -586,7 +586,7 @@ class TestInvocationVariants(object):
|
||||
assert result.ret == 0
|
||||
result.stdout.fnmatch_lines(["*2 passed*"])
|
||||
|
||||
monkeypatch.setenv("PYTHONPATH", join_pythonpath(testdir))
|
||||
monkeypatch.setenv("PYTHONPATH", str(join_pythonpath(testdir)))
|
||||
result = testdir.runpytest("--pyargs", "tpkg.test_missing", syspathinsert=True)
|
||||
assert result.ret != 0
|
||||
result.stderr.fnmatch_lines(["*not*found*test_missing*"])
|
||||
|
||||
@@ -129,7 +129,7 @@ def test_source_strip_multiline():
|
||||
def test_syntaxerror_rerepresentation():
|
||||
ex = pytest.raises(SyntaxError, _pytest._code.compile, "xyz xyz")
|
||||
assert ex.value.lineno == 1
|
||||
assert ex.value.offset in (4, 7) # XXX pypy/jython versus cpython?
|
||||
assert ex.value.offset in (4, 5, 7) # XXX pypy/jython versus cpython?
|
||||
assert ex.value.text.strip(), "x x"
|
||||
|
||||
|
||||
|
||||
@@ -246,21 +246,12 @@ def test_pytest_catchlog_deprecated(testdir, plugin):
|
||||
def test_pytest_plugins_in_non_top_level_conftest_deprecated(testdir):
|
||||
from _pytest.deprecated import PYTEST_PLUGINS_FROM_NON_TOP_LEVEL_CONFTEST
|
||||
|
||||
subdirectory = testdir.tmpdir.join("subdirectory")
|
||||
subdirectory.mkdir()
|
||||
# create the inner conftest with makeconftest and then move it to the subdirectory
|
||||
testdir.makeconftest(
|
||||
"""
|
||||
testdir.makepyfile(
|
||||
**{
|
||||
"subdirectory/conftest.py": """
|
||||
pytest_plugins=['capture']
|
||||
"""
|
||||
)
|
||||
testdir.tmpdir.join("conftest.py").move(subdirectory.join("conftest.py"))
|
||||
# make the top level conftest
|
||||
testdir.makeconftest(
|
||||
"""
|
||||
import warnings
|
||||
warnings.filterwarnings('always', category=DeprecationWarning)
|
||||
"""
|
||||
}
|
||||
)
|
||||
testdir.makepyfile(
|
||||
"""
|
||||
@@ -268,7 +259,7 @@ def test_pytest_plugins_in_non_top_level_conftest_deprecated(testdir):
|
||||
pass
|
||||
"""
|
||||
)
|
||||
res = testdir.runpytest_subprocess()
|
||||
res = testdir.runpytest()
|
||||
assert res.ret == 0
|
||||
msg = str(PYTEST_PLUGINS_FROM_NON_TOP_LEVEL_CONFTEST).splitlines()[0]
|
||||
res.stdout.fnmatch_lines(
|
||||
@@ -278,6 +269,34 @@ def test_pytest_plugins_in_non_top_level_conftest_deprecated(testdir):
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("use_pyargs", [True, False])
|
||||
def test_pytest_plugins_in_non_top_level_conftest_deprecated_pyargs(
|
||||
testdir, use_pyargs
|
||||
):
|
||||
"""When using --pyargs, do not emit the warning about non-top-level conftest warnings (#4039, #4044)"""
|
||||
from _pytest.deprecated import PYTEST_PLUGINS_FROM_NON_TOP_LEVEL_CONFTEST
|
||||
|
||||
files = {
|
||||
"src/pkg/__init__.py": "",
|
||||
"src/pkg/conftest.py": "",
|
||||
"src/pkg/test_root.py": "def test(): pass",
|
||||
"src/pkg/sub/__init__.py": "",
|
||||
"src/pkg/sub/conftest.py": "pytest_plugins=['capture']",
|
||||
"src/pkg/sub/test_bar.py": "def test(): pass",
|
||||
}
|
||||
testdir.makepyfile(**files)
|
||||
testdir.syspathinsert(testdir.tmpdir.join("src"))
|
||||
|
||||
args = ("--pyargs", "pkg") if use_pyargs else ()
|
||||
res = testdir.runpytest(*args)
|
||||
assert res.ret == 0
|
||||
msg = str(PYTEST_PLUGINS_FROM_NON_TOP_LEVEL_CONFTEST).splitlines()[0]
|
||||
if use_pyargs:
|
||||
assert msg not in res.stdout.str()
|
||||
else:
|
||||
res.stdout.fnmatch_lines("*{msg}*".format(msg=msg))
|
||||
|
||||
|
||||
def test_pytest_plugins_in_non_top_level_conftest_deprecated_no_top_level_conftest(
|
||||
testdir
|
||||
):
|
||||
|
||||
@@ -1050,6 +1050,48 @@ class TestAssertionRewriteHookDetails(object):
|
||||
result = testdir.runpytest("-s")
|
||||
result.stdout.fnmatch_lines(["* 1 passed*"])
|
||||
|
||||
def test_reload_reloads(self, testdir):
|
||||
"""Reloading a module after change picks up the change."""
|
||||
testdir.tmpdir.join("file.py").write(
|
||||
textwrap.dedent(
|
||||
"""
|
||||
def reloaded():
|
||||
return False
|
||||
|
||||
def rewrite_self():
|
||||
with open(__file__, 'w') as self:
|
||||
self.write('def reloaded(): return True')
|
||||
"""
|
||||
)
|
||||
)
|
||||
testdir.tmpdir.join("pytest.ini").write(
|
||||
textwrap.dedent(
|
||||
"""
|
||||
[pytest]
|
||||
python_files = *.py
|
||||
"""
|
||||
)
|
||||
)
|
||||
|
||||
testdir.makepyfile(
|
||||
test_fun="""
|
||||
import sys
|
||||
try:
|
||||
from imp import reload
|
||||
except ImportError:
|
||||
pass
|
||||
|
||||
def test_loader():
|
||||
import file
|
||||
assert not file.reloaded()
|
||||
file.rewrite_self()
|
||||
reload(file)
|
||||
assert file.reloaded()
|
||||
"""
|
||||
)
|
||||
result = testdir.runpytest("-s")
|
||||
result.stdout.fnmatch_lines(["* 1 passed*"])
|
||||
|
||||
def test_get_data_support(self, testdir):
|
||||
"""Implement optional PEP302 api (#808).
|
||||
"""
|
||||
|
||||
@@ -215,7 +215,7 @@ def test_cache_show(testdir):
|
||||
|
||||
class TestLastFailed(object):
|
||||
def test_lastfailed_usecase(self, testdir, monkeypatch):
|
||||
monkeypatch.setenv("PYTHONDONTWRITEBYTECODE", 1)
|
||||
monkeypatch.setenv("PYTHONDONTWRITEBYTECODE", "1")
|
||||
p = testdir.makepyfile(
|
||||
"""
|
||||
def test_1():
|
||||
@@ -301,7 +301,7 @@ class TestLastFailed(object):
|
||||
assert "test_a.py" not in result.stdout.str()
|
||||
|
||||
def test_lastfailed_difference_invocations(self, testdir, monkeypatch):
|
||||
monkeypatch.setenv("PYTHONDONTWRITEBYTECODE", 1)
|
||||
monkeypatch.setenv("PYTHONDONTWRITEBYTECODE", "1")
|
||||
testdir.makepyfile(
|
||||
test_a="""\
|
||||
def test_a1():
|
||||
@@ -335,7 +335,7 @@ class TestLastFailed(object):
|
||||
result.stdout.fnmatch_lines(["*1 failed*1 desel*"])
|
||||
|
||||
def test_lastfailed_usecase_splice(self, testdir, monkeypatch):
|
||||
monkeypatch.setenv("PYTHONDONTWRITEBYTECODE", 1)
|
||||
monkeypatch.setenv("PYTHONDONTWRITEBYTECODE", "1")
|
||||
testdir.makepyfile(
|
||||
"""\
|
||||
def test_1():
|
||||
@@ -474,8 +474,8 @@ class TestLastFailed(object):
|
||||
)
|
||||
|
||||
def rlf(fail_import, fail_run):
|
||||
monkeypatch.setenv("FAILIMPORT", fail_import)
|
||||
monkeypatch.setenv("FAILTEST", fail_run)
|
||||
monkeypatch.setenv("FAILIMPORT", str(fail_import))
|
||||
monkeypatch.setenv("FAILTEST", str(fail_run))
|
||||
|
||||
testdir.runpytest("-q")
|
||||
config = testdir.parseconfigure()
|
||||
@@ -519,8 +519,8 @@ class TestLastFailed(object):
|
||||
)
|
||||
|
||||
def rlf(fail_import, fail_run, args=()):
|
||||
monkeypatch.setenv("FAILIMPORT", fail_import)
|
||||
monkeypatch.setenv("FAILTEST", fail_run)
|
||||
monkeypatch.setenv("FAILIMPORT", str(fail_import))
|
||||
monkeypatch.setenv("FAILTEST", str(fail_run))
|
||||
|
||||
result = testdir.runpytest("-q", "--lf", *args)
|
||||
config = testdir.parseconfigure()
|
||||
|
||||
@@ -30,6 +30,7 @@ def conftest_setinitial(conftest, args, confcutdir=None):
|
||||
self.file_or_dir = args
|
||||
self.confcutdir = str(confcutdir)
|
||||
self.noconftest = False
|
||||
self.pyargs = False
|
||||
|
||||
conftest._set_initial_conftests(Namespace())
|
||||
|
||||
|
||||
@@ -850,7 +850,7 @@ def test_logxml_path_expansion(tmpdir, monkeypatch):
|
||||
assert xml_tilde.logfile == home_tilde
|
||||
|
||||
# this is here for when $HOME is not set correct
|
||||
monkeypatch.setenv("HOME", tmpdir)
|
||||
monkeypatch.setenv("HOME", str(tmpdir))
|
||||
home_var = os.path.normpath(os.path.expandvars("$HOME/test.xml"))
|
||||
|
||||
xml_var = LogXML("$HOME%stest.xml" % tmpdir.sep, None)
|
||||
|
||||
@@ -799,6 +799,18 @@ class TestFunctional(object):
|
||||
deselected_tests = dlist[0].items
|
||||
assert len(deselected_tests) == 2
|
||||
|
||||
def test_invalid_m_option(self, testdir):
|
||||
testdir.makepyfile(
|
||||
"""
|
||||
def test_a():
|
||||
pass
|
||||
"""
|
||||
)
|
||||
result = testdir.runpytest("-m bogus/")
|
||||
result.stdout.fnmatch_lines(
|
||||
["INTERNALERROR> Marker expression must be valid Python!"]
|
||||
)
|
||||
|
||||
def test_keywords_at_node_level(self, testdir):
|
||||
testdir.makepyfile(
|
||||
"""
|
||||
|
||||
@@ -3,6 +3,8 @@ import os
|
||||
import sys
|
||||
import textwrap
|
||||
|
||||
import six
|
||||
|
||||
import pytest
|
||||
from _pytest.monkeypatch import MonkeyPatch
|
||||
|
||||
@@ -163,7 +165,8 @@ def test_delitem():
|
||||
|
||||
def test_setenv():
|
||||
monkeypatch = MonkeyPatch()
|
||||
monkeypatch.setenv("XYZ123", 2)
|
||||
with pytest.warns(pytest.PytestWarning):
|
||||
monkeypatch.setenv("XYZ123", 2)
|
||||
import os
|
||||
|
||||
assert os.environ["XYZ123"] == "2"
|
||||
@@ -192,13 +195,49 @@ def test_delenv():
|
||||
del os.environ[name]
|
||||
|
||||
|
||||
class TestEnvironWarnings(object):
|
||||
"""
|
||||
os.environ keys and values should be native strings, otherwise it will cause problems with other modules (notably
|
||||
subprocess). On Python 2 os.environ accepts anything without complaining, while Python 3 does the right thing
|
||||
and raises an error.
|
||||
"""
|
||||
|
||||
VAR_NAME = u"PYTEST_INTERNAL_MY_VAR"
|
||||
|
||||
@pytest.mark.skipif(six.PY3, reason="Python 2 only test")
|
||||
def test_setenv_unicode_key(self, monkeypatch):
|
||||
with pytest.warns(
|
||||
pytest.PytestWarning,
|
||||
match="Environment variable name {!r} should be str".format(self.VAR_NAME),
|
||||
):
|
||||
monkeypatch.setenv(self.VAR_NAME, "2")
|
||||
|
||||
@pytest.mark.skipif(six.PY3, reason="Python 2 only test")
|
||||
def test_delenv_unicode_key(self, monkeypatch):
|
||||
with pytest.warns(
|
||||
pytest.PytestWarning,
|
||||
match="Environment variable name {!r} should be str".format(self.VAR_NAME),
|
||||
):
|
||||
monkeypatch.delenv(self.VAR_NAME, raising=False)
|
||||
|
||||
def test_setenv_non_str_warning(self, monkeypatch):
|
||||
value = 2
|
||||
msg = (
|
||||
"Environment variable value {!r} should be str, converted to str implicitly"
|
||||
)
|
||||
with pytest.warns(pytest.PytestWarning, match=msg.format(value)):
|
||||
monkeypatch.setenv(str(self.VAR_NAME), value)
|
||||
|
||||
|
||||
def test_setenv_prepend():
|
||||
import os
|
||||
|
||||
monkeypatch = MonkeyPatch()
|
||||
monkeypatch.setenv("XYZ123", 2, prepend="-")
|
||||
with pytest.warns(pytest.PytestWarning):
|
||||
monkeypatch.setenv("XYZ123", 2, prepend="-")
|
||||
assert os.environ["XYZ123"] == "2"
|
||||
monkeypatch.setenv("XYZ123", 3, prepend="-")
|
||||
with pytest.warns(pytest.PytestWarning):
|
||||
monkeypatch.setenv("XYZ123", 3, prepend="-")
|
||||
assert os.environ["XYZ123"] == "3-2"
|
||||
monkeypatch.undo()
|
||||
assert "XYZ123" not in os.environ
|
||||
|
||||
@@ -681,14 +681,22 @@ def test_pass_reporting_on_fail(testdir):
|
||||
def test_pass_output_reporting(testdir):
|
||||
testdir.makepyfile(
|
||||
"""
|
||||
def test_pass_output():
|
||||
def test_pass_has_output():
|
||||
print("Four score and seven years ago...")
|
||||
def test_pass_no_output():
|
||||
pass
|
||||
"""
|
||||
)
|
||||
result = testdir.runpytest()
|
||||
assert "Four score and seven years ago..." not in result.stdout.str()
|
||||
s = result.stdout.str()
|
||||
assert "test_pass_has_output" not in s
|
||||
assert "Four score and seven years ago..." not in s
|
||||
assert "test_pass_no_output" not in s
|
||||
result = testdir.runpytest("-rP")
|
||||
result.stdout.fnmatch_lines(["Four score and seven years ago..."])
|
||||
result.stdout.fnmatch_lines(
|
||||
["*test_pass_has_output*", "Four score and seven years ago..."]
|
||||
)
|
||||
assert "test_pass_no_output" not in result.stdout.str()
|
||||
|
||||
|
||||
def test_color_yes(testdir):
|
||||
|
||||
Reference in New Issue
Block a user