[Pytest-commit] commit/pytest: 3 new changesets
commits-noreply at bitbucket.org
commits-noreply at bitbucket.org
Sat Jul 6 16:03:28 CEST 2013
3 new commits in pytest:
https://bitbucket.org/hpk42/pytest/commits/bca2dc5e59dd/
Changeset: bca2dc5e59dd
User: katarzynaanna
Date: 2013-07-06 15:43:59
Summary: improved reporting
added intermediate level of quiet reporting:
* -q now shows short summary (# passed/failed tests + time)
* the former -q is now -qq
Affected #: 2 files
diff -r 29461bb5660a9c38aed9a8762401afa8f9188149 -r bca2dc5e59ddfe825771be634a74bf79598bcd5e _pytest/terminal.py
--- a/_pytest/terminal.py
+++ b/_pytest/terminal.py
@@ -44,7 +44,7 @@
pass
else:
config._cleanup.append(lambda: newstdout.close())
- assert stdout.encoding == newstdout.encoding
+ assert stdout.encoding == newstdout.encoding
stdout = newstdout
reporter = TerminalReporter(config, stdout)
@@ -105,7 +105,7 @@
self.hasmarkup = self._tw.hasmarkup
def hasopt(self, char):
- char = {'xfailed': 'x', 'skipped': 's'}.get(char,char)
+ char = {'xfailed': 'x', 'skipped': 's'}.get(char, char)
return char in self.reportchars
def write_fspath_result(self, fspath, res):
@@ -154,7 +154,7 @@
def pytest_plugin_registered(self, plugin):
if self.config.option.traceconfig:
- msg = "PLUGIN registered: %s" %(plugin,)
+ msg = "PLUGIN registered: %s" % (plugin,)
# XXX this event may happen during setup/teardown time
# which unfortunately captures our output here
# which garbles our output if we use self.write_line
@@ -209,7 +209,7 @@
self.currentfspath = -2
def pytest_collection(self):
- if not self.hasmarkup and self.config.option.verbose >=1:
+ if not self.hasmarkup and self.config.option.verbose >= 1:
self.write("collecting ... ", bold=True)
def pytest_collectreport(self, report):
@@ -325,8 +325,8 @@
stack.append(col)
#if col.name == "()":
# continue
- indent = (len(stack)-1) * " "
- self._tw.line("%s%s" %(indent, col))
+ indent = (len(stack) - 1) * " "
+ self._tw.line("%s%s" % (indent, col))
def pytest_sessionfinish(self, exitstatus, __multicall__):
__multicall__.execute()
@@ -452,9 +452,9 @@
if key: # setup/teardown reports have an empty key, ignore them
val = self.stats.get(key, None)
if val:
- parts.append("%d %s" %(len(val), key))
+ parts.append("%d %s" % (len(val), key))
line = ", ".join(parts)
- msg = "%s in %.2f seconds" %(line, session_duration)
+ msg = "%s in %.2f seconds" % (line, session_duration)
if self.verbosity >= 0:
markup = dict(bold=True)
if 'failed' in self.stats:
@@ -462,6 +462,10 @@
else:
markup['green'] = True
self.write_sep("=", msg, **markup)
+ if self.verbosity == -1:
+ if line:
+ self.write("%s, " % line)
+ self.write("time: %.2f seconds\n" % session_duration)
#else:
# self.write_line(msg, bold=True)
@@ -475,7 +479,7 @@
if m:
l.append("-m %r" % m)
if l:
- self.write_sep("=", "%d tests deselected by %r" %(
+ self.write_sep("=", "%d tests deselected by %r" % (
len(self.stats['deselected']), " ".join(l)), bold=True)
def repr_pythonversion(v=None):
diff -r 29461bb5660a9c38aed9a8762401afa8f9188149 -r bca2dc5e59ddfe825771be634a74bf79598bcd5e testing/test_terminal.py
--- a/testing/test_terminal.py
+++ b/testing/test_terminal.py
@@ -1,7 +1,7 @@
"""
terminal reporting of the full testing process.
"""
-import pytest,py
+import pytest, py
import sys
from _pytest.terminal import TerminalReporter, repr_pythonversion, getreportopt
@@ -32,7 +32,7 @@
metafunc.addcall(id="verbose",
funcargs={'option': Option(verbose=True)})
metafunc.addcall(id="quiet",
- funcargs={'option': Option(verbose=-1)})
+ funcargs={'option': Option(verbose= -1)})
metafunc.addcall(id="fulltrace",
funcargs={'option': Option(fulltrace=True)})
@@ -286,7 +286,7 @@
try:
monkeypatch.setattr(sys, 'version_info', (2, 5, 1, 'final', 0))
assert repr_pythonversion() == "2.5.1-final-0"
- py.std.sys.version_info = x = (2,3)
+ py.std.sys.version_info = x = (2, 3)
assert repr_pythonversion() == str(x)
finally:
monkeypatch.undo() # do this early as pytest can get confused
@@ -411,7 +411,7 @@
verinfo = ".".join(map(str, py.std.sys.version_info[:3]))
result.stdout.fnmatch_lines([
"*===== test session starts ====*",
- "platform %s -- Python %s*" %(
+ "platform %s -- Python %s*" % (
py.std.sys.platform, verinfo), # , py.std.sys.executable),
"*test_header_trailer_info.py .",
"=* 1 passed in *.[0-9][0-9] seconds *=",
@@ -473,6 +473,17 @@
assert 'test session starts' not in s
assert p1.basename not in s
assert "===" not in s
+ assert "passed" in s
+
+ def test_more_quiet_reporting(self, testdir):
+ p1 = testdir.makepyfile("def test_pass(): pass")
+ result = testdir.runpytest(p1, '-qq')
+ s = result.stdout.str()
+ assert 'test session starts' not in s
+ assert p1.basename not in s
+ assert "===" not in s
+ assert "passed" not in s
+
def test_fail_extra_reporting(testdir):
p = testdir.makepyfile("def test_this(): assert 0")
@@ -679,5 +690,5 @@
""")
result = testdir.runpytest("--tb=native")
result.stdout.fnmatch_lines([
- '*File *test_tbstyle_native_setup_error.py", line *, in setup_error_fixture*'
+ '*File *test_tbstyle_native_setup_error.py", line *, in setup_error_fixture*'
])
https://bitbucket.org/hpk42/pytest/commits/71ae07462c66/
Changeset: 71ae07462c66
User: katarzynaanna
Date: 2013-07-06 15:54:33
Summary: merge
Affected #: 5 files
diff -r bca2dc5e59ddfe825771be634a74bf79598bcd5e -r 71ae07462c66ccea05901442fb0461d7834aea1d CHANGELOG
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,6 +1,9 @@
Changes between 2.3.5 and 2.4.DEV
-----------------------------------
+- fix issue300 - Fix order of conftest loading when starting py.test
+ in a subdirectory.
+
- fix issue323 - sorting of many module-scoped arg parametrizations
- add support for setUpModule/tearDownModule detection, thanks Brian Okken.
diff -r bca2dc5e59ddfe825771be634a74bf79598bcd5e -r 71ae07462c66ccea05901442fb0461d7834aea1d _pytest/config.py
--- a/_pytest/config.py
+++ b/_pytest/config.py
@@ -196,27 +196,20 @@
self.getconftestmodules(x)
def getconftestmodules(self, path):
- """ return a list of imported conftest modules for the given path. """
try:
clist = self._path2confmods[path]
except KeyError:
if path is None:
- raise ValueError("missing default confest.")
- dp = path.dirpath()
+ raise ValueError("missing default conftest.")
clist = []
- if dp != path:
- cutdir = self._confcutdir
- if cutdir and path != cutdir and not path.relto(cutdir):
- pass
- else:
- conftestpath = path.join("conftest.py")
- if conftestpath.check(file=1):
- clist.append(self.importconftest(conftestpath))
- clist[:0] = self.getconftestmodules(dp)
+ for parent in path.parts():
+ if self._confcutdir and self._confcutdir.relto(parent):
+ continue
+ conftestpath = parent.join("conftest.py")
+ if conftestpath.check(file=1):
+ clist.append(self.importconftest(conftestpath))
self._path2confmods[path] = clist
- # be defensive: avoid changes from caller side to
- # affect us by always returning a copy of the actual list
- return clist[:]
+ return clist
def rget(self, name, path=None):
mod, value = self.rget_with_confmod(name, path)
diff -r bca2dc5e59ddfe825771be634a74bf79598bcd5e -r 71ae07462c66ccea05901442fb0461d7834aea1d testing/python/fixture.py
--- a/testing/python/fixture.py
+++ b/testing/python/fixture.py
@@ -102,6 +102,77 @@
"*2 passed*"
])
+ def test_extend_fixture_module_class(self, testdir):
+ testfile = testdir.makepyfile("""
+ import pytest
+
+ @pytest.fixture
+ def spam():
+ return 'spam'
+
+ class TestSpam:
+
+ @pytest.fixture
+ def spam(self, spam):
+ return spam * 2
+
+ def test_spam(self, spam):
+ assert spam == 'spamspam'
+ """)
+ result = testdir.runpytest()
+ result.stdout.fnmatch_lines(["*1 passed*"])
+ result = testdir.runpytest(testfile)
+ result.stdout.fnmatch_lines(["*1 passed*"])
+
+ def test_extend_fixture_conftest_module(self, testdir):
+ testdir.makeconftest("""
+ import pytest
+
+ @pytest.fixture
+ def spam():
+ return 'spam'
+ """)
+ testfile = testdir.makepyfile("""
+ import pytest
+
+ @pytest.fixture
+ def spam(spam):
+ return spam * 2
+
+ def test_spam(spam):
+ assert spam == 'spamspam'
+ """)
+ result = testdir.runpytest()
+ result.stdout.fnmatch_lines(["*1 passed*"])
+ result = testdir.runpytest(testfile)
+ result.stdout.fnmatch_lines(["*1 passed*"])
+
+ def test_extend_fixture_conftest_conftest(self, testdir):
+ testdir.makeconftest("""
+ import pytest
+
+ @pytest.fixture
+ def spam():
+ return 'spam'
+ """)
+ pkg = testdir.mkpydir("pkg")
+ pkg.join("conftest.py").write(py.code.Source("""
+ import pytest
+
+ @pytest.fixture
+ def spam(spam):
+ return spam * 2
+ """))
+ testfile = pkg.join("test_spam.py")
+ testfile.write(py.code.Source("""
+ def test_spam(spam):
+ assert spam == "spamspam"
+ """))
+ result = testdir.runpytest()
+ result.stdout.fnmatch_lines(["*1 passed*"])
+ result = testdir.runpytest(testfile)
+ result.stdout.fnmatch_lines(["*1 passed*"])
+
def test_funcarg_lookup_error(self, testdir):
p = testdir.makepyfile("""
def test_lookup_error(unknown):
diff -r bca2dc5e59ddfe825771be634a74bf79598bcd5e -r 71ae07462c66ccea05901442fb0461d7834aea1d testing/test_conftest.py
--- a/testing/test_conftest.py
+++ b/testing/test_conftest.py
@@ -204,3 +204,14 @@
"""))
result = testdir.runpytest("-h", "--confcutdir=%s" % x, x)
result.stdout.fnmatch_lines(["*--xyz*"])
+
+def test_conftest_import_order(testdir, monkeypatch):
+ ct1 = testdir.makeconftest("")
+ sub = testdir.mkdir("sub")
+ ct2 = sub.join("conftest.py")
+ ct2.write("")
+ def impct(p):
+ return p
+ conftest = Conftest()
+ monkeypatch.setattr(conftest, 'importconftest', impct)
+ assert conftest.getconftestmodules(sub) == [ct1, ct2]
diff -r bca2dc5e59ddfe825771be634a74bf79598bcd5e -r 71ae07462c66ccea05901442fb0461d7834aea1d testing/test_terminal.py
--- a/testing/test_terminal.py
+++ b/testing/test_terminal.py
@@ -654,9 +654,9 @@
""")
result = testdir.runpytest("a")
result.stdout.fnmatch_lines([
+ "*hello: 42*",
"line1",
str(testdir.tmpdir),
- "*hello: 42*",
])
@pytest.mark.xfail("not hasattr(os, 'dup')")
https://bitbucket.org/hpk42/pytest/commits/c1bf2cd59fb7/
Changeset: c1bf2cd59fb7
User: hpk42
Date: 2013-07-06 16:03:27
Summary: Merged in katarzynaanna/pytest (pull request #42)
Improved reporting
Affected #: 2 files
diff -r c3a0a8895e55c89070142e3849959464d08514b6 -r c1bf2cd59fb7accc4835ff34ca8551b1155a1ae2 _pytest/terminal.py
--- a/_pytest/terminal.py
+++ b/_pytest/terminal.py
@@ -44,7 +44,7 @@
pass
else:
config._cleanup.append(lambda: newstdout.close())
- assert stdout.encoding == newstdout.encoding
+ assert stdout.encoding == newstdout.encoding
stdout = newstdout
reporter = TerminalReporter(config, stdout)
@@ -105,7 +105,7 @@
self.hasmarkup = self._tw.hasmarkup
def hasopt(self, char):
- char = {'xfailed': 'x', 'skipped': 's'}.get(char,char)
+ char = {'xfailed': 'x', 'skipped': 's'}.get(char, char)
return char in self.reportchars
def write_fspath_result(self, fspath, res):
@@ -154,7 +154,7 @@
def pytest_plugin_registered(self, plugin):
if self.config.option.traceconfig:
- msg = "PLUGIN registered: %s" %(plugin,)
+ msg = "PLUGIN registered: %s" % (plugin,)
# XXX this event may happen during setup/teardown time
# which unfortunately captures our output here
# which garbles our output if we use self.write_line
@@ -209,7 +209,7 @@
self.currentfspath = -2
def pytest_collection(self):
- if not self.hasmarkup and self.config.option.verbose >=1:
+ if not self.hasmarkup and self.config.option.verbose >= 1:
self.write("collecting ... ", bold=True)
def pytest_collectreport(self, report):
@@ -325,8 +325,8 @@
stack.append(col)
#if col.name == "()":
# continue
- indent = (len(stack)-1) * " "
- self._tw.line("%s%s" %(indent, col))
+ indent = (len(stack) - 1) * " "
+ self._tw.line("%s%s" % (indent, col))
def pytest_sessionfinish(self, exitstatus, __multicall__):
__multicall__.execute()
@@ -452,9 +452,9 @@
if key: # setup/teardown reports have an empty key, ignore them
val = self.stats.get(key, None)
if val:
- parts.append("%d %s" %(len(val), key))
+ parts.append("%d %s" % (len(val), key))
line = ", ".join(parts)
- msg = "%s in %.2f seconds" %(line, session_duration)
+ msg = "%s in %.2f seconds" % (line, session_duration)
if self.verbosity >= 0:
markup = dict(bold=True)
if 'failed' in self.stats:
@@ -462,6 +462,10 @@
else:
markup['green'] = True
self.write_sep("=", msg, **markup)
+ if self.verbosity == -1:
+ if line:
+ self.write("%s, " % line)
+ self.write("time: %.2f seconds\n" % session_duration)
#else:
# self.write_line(msg, bold=True)
@@ -475,7 +479,7 @@
if m:
l.append("-m %r" % m)
if l:
- self.write_sep("=", "%d tests deselected by %r" %(
+ self.write_sep("=", "%d tests deselected by %r" % (
len(self.stats['deselected']), " ".join(l)), bold=True)
def repr_pythonversion(v=None):
diff -r c3a0a8895e55c89070142e3849959464d08514b6 -r c1bf2cd59fb7accc4835ff34ca8551b1155a1ae2 testing/test_terminal.py
--- a/testing/test_terminal.py
+++ b/testing/test_terminal.py
@@ -1,7 +1,7 @@
"""
terminal reporting of the full testing process.
"""
-import pytest,py
+import pytest, py
import sys
from _pytest.terminal import TerminalReporter, repr_pythonversion, getreportopt
@@ -32,7 +32,7 @@
metafunc.addcall(id="verbose",
funcargs={'option': Option(verbose=True)})
metafunc.addcall(id="quiet",
- funcargs={'option': Option(verbose=-1)})
+ funcargs={'option': Option(verbose= -1)})
metafunc.addcall(id="fulltrace",
funcargs={'option': Option(fulltrace=True)})
@@ -286,7 +286,7 @@
try:
monkeypatch.setattr(sys, 'version_info', (2, 5, 1, 'final', 0))
assert repr_pythonversion() == "2.5.1-final-0"
- py.std.sys.version_info = x = (2,3)
+ py.std.sys.version_info = x = (2, 3)
assert repr_pythonversion() == str(x)
finally:
monkeypatch.undo() # do this early as pytest can get confused
@@ -411,7 +411,7 @@
verinfo = ".".join(map(str, py.std.sys.version_info[:3]))
result.stdout.fnmatch_lines([
"*===== test session starts ====*",
- "platform %s -- Python %s*" %(
+ "platform %s -- Python %s*" % (
py.std.sys.platform, verinfo), # , py.std.sys.executable),
"*test_header_trailer_info.py .",
"=* 1 passed in *.[0-9][0-9] seconds *=",
@@ -473,6 +473,17 @@
assert 'test session starts' not in s
assert p1.basename not in s
assert "===" not in s
+ assert "passed" in s
+
+ def test_more_quiet_reporting(self, testdir):
+ p1 = testdir.makepyfile("def test_pass(): pass")
+ result = testdir.runpytest(p1, '-qq')
+ s = result.stdout.str()
+ assert 'test session starts' not in s
+ assert p1.basename not in s
+ assert "===" not in s
+ assert "passed" not in s
+
def test_fail_extra_reporting(testdir):
p = testdir.makepyfile("def test_this(): assert 0")
@@ -679,5 +690,5 @@
""")
result = testdir.runpytest("--tb=native")
result.stdout.fnmatch_lines([
- '*File *test_tbstyle_native_setup_error.py", line *, in setup_error_fixture*'
+ '*File *test_tbstyle_native_setup_error.py", line *, in setup_error_fixture*'
])
Repository URL: https://bitbucket.org/hpk42/pytest/
--
This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.
More information about the pytest-commit
mailing list