This commit is contained in:
holger krekel 2013-07-06 16:03:48 +02:00
commit 31421cb6d7
6 changed files with 79 additions and 14 deletions

32
.gitignore vendored Normal file
View File

@ -0,0 +1,32 @@
# Automatically generated by `hgimportsvn`
.svn
.hgsvn
# Ignore local virtualenvs
lib/
bin/
include/
.Python/
# These lines are suggested according to the svn:ignore property
# Feel free to enable them by uncommenting them
*.pyc
*.pyo
*.swp
*.html
*.class
*.orig
*~
doc/*/_build
build/
dist/
*.egg-info
issue/
env/
3rdparty/
.tox
.cache
.coverage
.ropeproject

10
.travis.yml Normal file
View File

@ -0,0 +1,10 @@
language: python
# command to install dependencies
install: "pip install -e . detox"
# # command to run tests
script: detox --recreate
notifications:
irc:
- "chat.freenode.net#pylib"
email:
- pytest-commit@python.org

View File

@ -16,6 +16,9 @@ scales to support complex functional testing. It provides
- many `external plugins <http://pytest.org/latest/plugins.html#installing-external-plugins-searching>`_. - many `external plugins <http://pytest.org/latest/plugins.html#installing-external-plugins-searching>`_.
.. image:: https://secure.travis-ci.org/bubenkoff/pytest.png?branch=travis-integration
:target: http://travis-ci.org/bubenkoff/pytest
A simple example for a test:: A simple example for a test::
# content of test_module.py # content of test_module.py

View File

@ -44,7 +44,7 @@ def pytest_configure(config):
pass pass
else: else:
config._cleanup.append(lambda: newstdout.close()) config._cleanup.append(lambda: newstdout.close())
assert stdout.encoding == newstdout.encoding assert stdout.encoding == newstdout.encoding
stdout = newstdout stdout = newstdout
reporter = TerminalReporter(config, stdout) reporter = TerminalReporter(config, stdout)
@ -105,7 +105,7 @@ class TerminalReporter:
self.hasmarkup = self._tw.hasmarkup self.hasmarkup = self._tw.hasmarkup
def hasopt(self, char): 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 return char in self.reportchars
def write_fspath_result(self, fspath, res): def write_fspath_result(self, fspath, res):
@ -154,7 +154,7 @@ class TerminalReporter:
def pytest_plugin_registered(self, plugin): def pytest_plugin_registered(self, plugin):
if self.config.option.traceconfig: if self.config.option.traceconfig:
msg = "PLUGIN registered: %s" %(plugin,) msg = "PLUGIN registered: %s" % (plugin,)
# XXX this event may happen during setup/teardown time # XXX this event may happen during setup/teardown time
# which unfortunately captures our output here # which unfortunately captures our output here
# which garbles our output if we use self.write_line # which garbles our output if we use self.write_line
@ -209,7 +209,7 @@ class TerminalReporter:
self.currentfspath = -2 self.currentfspath = -2
def pytest_collection(self): 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) self.write("collecting ... ", bold=True)
def pytest_collectreport(self, report): def pytest_collectreport(self, report):
@ -325,8 +325,8 @@ class TerminalReporter:
stack.append(col) stack.append(col)
#if col.name == "()": #if col.name == "()":
# continue # continue
indent = (len(stack)-1) * " " indent = (len(stack) - 1) * " "
self._tw.line("%s%s" %(indent, col)) self._tw.line("%s%s" % (indent, col))
def pytest_sessionfinish(self, exitstatus, __multicall__): def pytest_sessionfinish(self, exitstatus, __multicall__):
__multicall__.execute() __multicall__.execute()
@ -452,9 +452,9 @@ class TerminalReporter:
if key: # setup/teardown reports have an empty key, ignore them if key: # setup/teardown reports have an empty key, ignore them
val = self.stats.get(key, None) val = self.stats.get(key, None)
if val: if val:
parts.append("%d %s" %(len(val), key)) parts.append("%d %s" % (len(val), key))
line = ", ".join(parts) line = ", ".join(parts)
msg = "%s in %.2f seconds" %(line, session_duration) msg = "%s in %.2f seconds" % (line, session_duration)
if self.verbosity >= 0: if self.verbosity >= 0:
markup = dict(bold=True) markup = dict(bold=True)
if 'failed' in self.stats: if 'failed' in self.stats:
@ -462,6 +462,10 @@ class TerminalReporter:
else: else:
markup['green'] = True markup['green'] = True
self.write_sep("=", msg, **markup) self.write_sep("=", msg, **markup)
if self.verbosity == -1:
if line:
self.write("%s, " % line)
self.write("time: %.2f seconds\n" % session_duration)
#else: #else:
# self.write_line(msg, bold=True) # self.write_line(msg, bold=True)
@ -475,7 +479,7 @@ class TerminalReporter:
if m: if m:
l.append("-m %r" % m) l.append("-m %r" % m)
if l: 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) len(self.stats['deselected']), " ".join(l)), bold=True)
def repr_pythonversion(v=None): def repr_pythonversion(v=None):

View File

@ -1,7 +1,7 @@
""" """
terminal reporting of the full testing process. terminal reporting of the full testing process.
""" """
import pytest,py import pytest, py
import sys import sys
from _pytest.terminal import TerminalReporter, repr_pythonversion, getreportopt from _pytest.terminal import TerminalReporter, repr_pythonversion, getreportopt
@ -32,7 +32,7 @@ def pytest_generate_tests(metafunc):
metafunc.addcall(id="verbose", metafunc.addcall(id="verbose",
funcargs={'option': Option(verbose=True)}) funcargs={'option': Option(verbose=True)})
metafunc.addcall(id="quiet", metafunc.addcall(id="quiet",
funcargs={'option': Option(verbose=-1)}) funcargs={'option': Option(verbose= -1)})
metafunc.addcall(id="fulltrace", metafunc.addcall(id="fulltrace",
funcargs={'option': Option(fulltrace=True)}) funcargs={'option': Option(fulltrace=True)})
@ -286,7 +286,7 @@ def test_repr_python_version(monkeypatch):
try: try:
monkeypatch.setattr(sys, 'version_info', (2, 5, 1, 'final', 0)) monkeypatch.setattr(sys, 'version_info', (2, 5, 1, 'final', 0))
assert repr_pythonversion() == "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) assert repr_pythonversion() == str(x)
finally: finally:
monkeypatch.undo() # do this early as pytest can get confused monkeypatch.undo() # do this early as pytest can get confused
@ -411,7 +411,7 @@ class TestTerminalFunctional:
verinfo = ".".join(map(str, py.std.sys.version_info[:3])) verinfo = ".".join(map(str, py.std.sys.version_info[:3]))
result.stdout.fnmatch_lines([ result.stdout.fnmatch_lines([
"*===== test session starts ====*", "*===== test session starts ====*",
"platform %s -- Python %s*" %( "platform %s -- Python %s*" % (
py.std.sys.platform, verinfo), # , py.std.sys.executable), py.std.sys.platform, verinfo), # , py.std.sys.executable),
"*test_header_trailer_info.py .", "*test_header_trailer_info.py .",
"=* 1 passed in *.[0-9][0-9] seconds *=", "=* 1 passed in *.[0-9][0-9] seconds *=",
@ -473,6 +473,17 @@ class TestTerminalFunctional:
assert 'test session starts' not in s assert 'test session starts' not in s
assert p1.basename not in s assert p1.basename not in s
assert "===" 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): def test_fail_extra_reporting(testdir):
p = testdir.makepyfile("def test_this(): assert 0") p = testdir.makepyfile("def test_this(): assert 0")

View File

@ -13,6 +13,10 @@ deps=
changedir=. changedir=.
commands= py.test --genscript=pytest1 commands= py.test --genscript=pytest1
[testenv:py25]
setenv =
PIP_INSECURE=1
[testenv:py27-xdist] [testenv:py27-xdist]
changedir=. changedir=.
basepython=python2.7 basepython=python2.7
@ -29,6 +33,7 @@ basepython=python2.7
deps=pytest-xdist deps=pytest-xdist
setenv= setenv=
PYTHONDONTWRITEBYTECODE=1 PYTHONDONTWRITEBYTECODE=1
distribute=true
commands= commands=
py.test -n3 -rfsxX \ py.test -n3 -rfsxX \
--junitxml={envlogdir}/junit-{envname}.xml {posargs:testing} --junitxml={envlogdir}/junit-{envname}.xml {posargs:testing}