Compare commits

...

35 Commits
2.2.2 ... 2.2.4

Author SHA1 Message Date
holger krekel
69fc6987ad upgrade inlined distribute_setup.py 2012-05-22 17:24:43 +02:00
holger krekel
0790f7a75f fix issue 144 - wrong classname in junitxml 2012-05-22 17:18:04 +02:00
Ronny Pfannschmidt
db8fbe7661 skip test for pyo on pypy since pypy doesnt do pyo 2012-05-22 16:20:58 +02:00
Jonathan Peirce
91c41cd6b3 minor fix to docs/usage 2012-05-22 12:24:53 +01:00
holger krekel
1bf1cfd07a fix help string for --paste 2012-05-19 10:54:12 +02:00
holger krekel
51d94a4a6e use higher difference on timing 2012-05-18 13:56:49 +02:00
holger krekel
e18abfd013 fix issue143 - call unconfigure/sessionfinish always when
configure/sessionstart where called

use exitcode 4 (instead of 3 which signaled an internal error)
when an initial directory/file was not found
2012-05-17 23:11:23 +02:00
holger krekel
6c7ea8191f fix wrong release version 2012-05-17 15:44:18 +02:00
holger krekel
329dca42a7 add release announcement 2012-05-17 15:25:58 +02:00
holger krekel
0362aaba5a require py-1.4.8 2012-05-17 08:47:50 +02:00
holger krekel
948dea8bb4 bump version to next release 2012-05-17 08:46:49 +02:00
Ronny Pfannschmidt
6155e9139d hande the trial todo class by using repr 2012-05-10 01:38:13 +02:00
holger krekel
6dd8405aed bump version 2012-05-10 00:34:47 +02:00
Ronny Pfannschmidt
c076f4e789 switch pastebin to bpaste.net, fixes #141 2012-05-08 16:13:25 +02:00
Ronny Pfannschmidt
d32a132b51 add the fix for issue 140 to CHANGELOG 2012-05-08 14:15:23 +02:00
Ronny Pfannschmidt
0e3779b14f strip bound wrappers of class setup/tardown, fixes #140
on python3 im_func is replaced by __func__
2012-05-06 23:03:16 +02:00
Benjamin Peterson
fe1c35f8d0 prepend the assertion rewriting hook, so as not to break when builtin import is explicitly on sys.meta_path 2012-05-05 17:31:05 -04:00
Benjamin Peterson
b4588f1798 escape the % operator in string formatting 2012-05-03 13:49:30 -04:00
Benjamin Peterson
64c7c1be15 use non-hacky dynamic package import method 2012-04-27 17:51:50 -04:00
Benjamin Peterson
1c817aa7bd don't use octal syntax, since its not py2/py3 compatible 2012-04-18 11:26:44 -04:00
Ronny Pfannschmidt
d02eaa8881 fix a import strange loop that affects pypy test appsupport on python2.5 2012-04-13 12:41:02 +02:00
holger krekel
b92176024c write down some thoughts on parametrization - still not completely clear what the next stage should look like ... 2012-03-31 10:01:03 -07:00
holger krekel
1c746e0819 merge 2012-03-31 10:12:11 -07:00
Ronny Pfannschmidt
166aae4418 word change in the docs fixes #130 2012-03-22 08:26:37 +01:00
holger krekel
58933aac2a try to better handle @unittest.expectedFailure decorator 2012-03-19 22:53:52 -07:00
Benjamin Peterson
45aa4e5229 remove unused import 2012-03-19 20:04:55 -04:00
holger krekel
e643e99586 bump version number to dev version 2012-03-19 08:53:08 -07:00
holger krekel
9f6d6f630d walk through issues 2012-03-19 06:56:35 -07:00
Ronny Pfannschmidt
812ba87f37 add acomment so highlighting won\'t fail 2012-03-15 15:22:13 +01:00
Ronny Pfannschmidt
2b0887fa5f document integration with setuptools/distribute test command and tests_require 2012-03-15 15:15:21 +01:00
Ronny Pfannschmidt
ee8d2f9950 junitxml: use a exclusive match on the legal ranges of xml for binary escaping, fixes issue 126 2012-03-09 13:12:18 +01:00
holger krekel
51d29cf4c6 mention 2.2.3 in 2.2.2 release announce 2012-02-05 23:54:20 -05:00
holger krekel
e378496b24 Added tag 2.2.3 for changeset 3c11c5c9776f 2012-02-05 23:39:00 -05:00
holger krekel
4d21274a29 release 2.2.3 to fix package contents (2.2.2 contained too many files) 2012-02-05 23:38:31 -05:00
holger krekel
705442cf4e Added tag 2.2.2 for changeset 92b916483c1e 2012-02-05 18:37:31 -05:00
30 changed files with 434 additions and 149 deletions

View File

@@ -46,3 +46,5 @@ e5e1746a197f0398356a43fbe2eebac9690f795d 2.1.0
12a05d59249f80276e25fd8b96e8e545b1332b7a 2.1.3
1522710369337d96bf9568569d5f0ca9b38a74e0 2.2.0
3da8cec6c5326ed27c144c9b6d7a64a648370005 2.2.1
92b916483c1e65a80dc80e3f7816b39e84b36a4d 2.2.2
3c11c5c9776f3c678719161e96cc0a08169c1cb8 2.2.3

View File

@@ -1,3 +1,25 @@
Changes between 2.2.3 and 2.2.4
-----------------------------------
- fix error message for rewritten assertions involving the % operator
- fix issue 126: correctly match all invalid xml characters for junitxml
binary escape
- fix issue with unittest: now @unittest.expectedFailure markers should
be processed correctly (you can also use @pytest.mark markers)
- document integration with the extended distribute/setuptools test commands
- fix issue 140: propperly get the real functions
of bound classmethods for setup/teardown_class
- fix issue #141: switch from the deceased paste.pocoo.org to bpaste.net
- fix issue #143: call unconfigure/sessionfinish always when
configure/sessionstart where called
- fix issue #144: better mangle test ids to junitxml classnames
- upgrade distribute_setup.py to 0.6.27
Changes between 2.2.2 and 2.2.3
----------------------------------------
- fix uploaded package to only include neccesary files
Changes between 2.2.1 and 2.2.2
----------------------------------------

View File

@@ -1,23 +1,124 @@
refine parametrize API in 2.2 series
improve / add to dependency/test resource injection
-------------------------------------------------------------
tags: critical feature 2.2
tags: wish feature docs
extend metafunc.parametrize to better support indirection
by specifying a setupfunc(request, val) which will _substitute_
the funcarg factory. Here is an example:
write up better examples showing the connection between
the two.
def setupdb(request, val):
refine parametrize API
-------------------------------------------------------------
tags: critical feature
extend metafunc.parametrize to directly support indirection, example:
def setupdb(request, config):
# setup "resource" based on test request and the values passed
# in to parametrize. setupfunc is called for each such value.
# you may use request.addfinalizer() or request.cached_setup ...
return db
return dynamic_setup_database(val)
@pytest.mark.parametrize("db", ["pg", "mysql"], setupfunc=setupdb)
def test_heavy_functional_test(db):
...
There would be no need to write funcarg factories for this example, only
to explain the attributes and functionality of "request".
There would be no need to write or explain funcarg factories and
their special __ syntax.
The examples and improvements should also show how to put the parametrize
decorator to a class, to a module or even to a directory. For the directory
part a conftest.py content like this::
pytestmark = [
@pytest.mark.parametrize_setup("db", ...),
]
probably makes sense in order to keep the declarative nature. This mirrors
the marker-mechanism with respect to a test module but puts it to a directory
scale.
When doing larger scoped parametrization it probably becomes neccessary
to allow parametrization to be ignored if the according parameter is not
used (currently any parametrized argument that is not present in a function will cause a ValueError). Example:
@pytest.mark.parametrize("db", ..., mustmatch=False)
means to not raise an error but simply ignore the parametrization
if the signature of a decorated function does not match. XXX is it
not sufficient to always allow non-matches?
unify item/request classes, generalize items
---------------------------------------------------------------
tags: 2.4 wish
in lieu of extended parametrization and the new way to specify resource
factories in terms of the parametrize decorator, consider unification
of the item and request class. This also is connected with allowing
funcargs in setup functions. Example of new item API:
item.getresource("db") # alias for request.getfuncargvalue
item.addfinalizer(...)
item.cached_setup(...)
item.applymarker(...)
test classes/modules could then use this api via::
def pytest_runtest_setup(item):
use item API ...
introduction of this new method needs to be _fully_ backward compatible -
and the documentation needs to change along to mention this new way of
doing things.
impl note: probably Request._fillfuncargs would be called from the
python plugins own pytest_runtest_setup(item) and would call
item.getresource(X) for all X in the funcargs of a function.
XXX is it possible to even put the above item API to Nodes, i.e. also
to Directorty/module/file/class collectors? Problem is that current
funcarg factories presume they are called with a per-function (even
per-funcarg-per-function) scope. Could there be small tweaks to the new
API that lift this restriction?
consider::
def setup_class(cls, tmpdir):
# would get a per-class tmpdir because tmpdir parametrization
# would know that it is called with a class scope
#
#
#
this looks very difficult because those setup functions are also used
by nose etc. Rather consider introduction of a new setup hook:
def setup_test(self, item):
self.db = item.cached_setup(..., scope='class')
self.tmpdir = item.getresource("tmpdir")
this should be compatible to unittest/nose and provide much of what
"testresources" provide. XXX This would not allow full parametrization
such that test function could be run multiple times with different
values. See "parametrized attributes" issue.
allow parametrized attributes on classes
--------------------------------------------------
tags: wish 2.4
example:
@pytest.mark.parametrize_attr("db", setupfunc, [1,2,3], scope="class")
@pytest.mark.parametrize_attr("tmp", setupfunc, scope="...")
class TestMe:
def test_hello(self):
access self.db ...
this would run the test_hello() function three times with three
different values for self.db. This could also work with unittest/nose
style tests, i.e. it leverages existing test suites without needing
to rewrite them. Together with the previously mentioned setup_test()
maybe the setupfunc could be ommitted?
checks / deprecations for next release
---------------------------------------------------------------
@@ -46,21 +147,9 @@ appropriately to avoid this issue. Moreover/Alternatively, we could
record which implementations of a hook succeeded and only call their
teardown.
do early-teardown of test modules
-----------------------------------------
tags: feature 2.3
currently teardowns are called when the next tests is setup
except for the function/method level where interally
"teardown_exact" tears down immediately. Generalize
this to perform the "neccessary" teardown compared to
the "next" test item during teardown - this should
get rid of some irritations because otherwise e.g.
prints of teardown-code appear in the setup of the next test.
consider and document __init__ file usage in test directories
---------------------------------------------------------------
tags: bug 2.3 core
tags: bug core
Currently, a test module is imported with its fully qualified
package path, determined by checking __init__ files upwards.
@@ -75,7 +164,7 @@ certain scenarios makes sense.
relax requirement to have tests/testing contain an __init__
----------------------------------------------------------------
tags: feature 2.3
tags: feature
bb: http://bitbucket.org/hpk42/py-trunk/issue/64
A local test run of a "tests" directory may work
@@ -86,7 +175,7 @@ i.e. port the nose-logic of unloading a test module.
customize test function collection
-------------------------------------------------------
tags: feature 2.3
tags: feature
- introduce py.test.mark.nocollect for not considering a function for
test collection at all. maybe also introduce a py.test.mark.test to
@@ -95,7 +184,7 @@ tags: feature 2.3
introduce pytest.mark.importorskip
-------------------------------------------------------
tags: feature 2.3
tags: feature
in addition to the imperative pytest.importorskip also introduce
a pytest.mark.importorskip so that the test count is more correct.
@@ -103,7 +192,7 @@ a pytest.mark.importorskip so that the test count is more correct.
introduce py.test.mark.platform
-------------------------------------------------------
tags: feature 2.3
tags: feature
Introduce nice-to-spell platform-skipping, examples:
@@ -120,7 +209,7 @@ interpreter versions.
pytest.mark.xfail signature change
-------------------------------------------------------
tags: feature 2.3
tags: feature
change to pytest.mark.xfail(reason, (optional)condition)
to better implement the word meaning. It also signals
@@ -128,36 +217,28 @@ better that we always have some kind of an implementation
reason that can be formualated.
Compatibility? how to introduce a new name/keep compat?
introduce py.test.mark registration
-----------------------------------------
tags: feature 2.3
introduce a hook that allows to register a named mark decorator
with documentation and add "py.test --marks" to get
a list of available marks. Deprecate "dynamic" mark
definitions.
allow to non-intrusively apply skipfs/xfail/marks
---------------------------------------------------
tags: feature 2.3
tags: feature
use case: mark a module or directory structures
to be skipped on certain platforms (i.e. no import
attempt will be made).
consider introducing a hook/mechanism that allows to apply marks
from conftests or plugins.
from conftests or plugins. (See extended parametrization)
explicit referencing of conftest.py files
-----------------------------------------
tags: feature 2.3
tags: feature
allow to name conftest.py files (in sub directories) that should
be imported early, as to include command line options.
improve central py.test ini file
----------------------------------
tags: feature 2.3
tags: feature
introduce more declarative configuration options:
- (to-be-collected test directories)
@@ -168,7 +249,7 @@ introduce more declarative configuration options:
new documentation
----------------------------------
tags: feature 2.3
tags: feature
- logo py.test
- examples for unittest or functional testing
@@ -177,23 +258,15 @@ tags: feature 2.3
have imported module mismatch honour relative paths
--------------------------------------------------------
tags: bug 2.3
tags: bug
With 1.1.1 py.test fails at least on windows if an import
is relative and compared against an absolute conftest.py
path. Normalize.
call termination with small timeout
-------------------------------------------------
tags: feature 2.3
test: testing/pytest/dist/test_dsession.py - test_terminate_on_hanging_node
Call gateway group termination with a small timeout if available.
Should make dist-testing less likely to leave lost processes.
consider globals: py.test.ensuretemp and config
--------------------------------------------------------------
tags: experimental-wish 2.3
tags: experimental-wish
consider deprecating py.test.ensuretemp and py.test.config
to further reduce py.test globality. Also consider
@@ -202,7 +275,7 @@ a plugin rather than being there from the start.
consider allowing funcargs for setup methods
--------------------------------------------------------------
tags: experimental-wish 2.3
tags: experimental-wish
Users have expressed the wish to have funcargs available to setup
functions. Experiment with allowing funcargs there - it might
@@ -225,7 +298,7 @@ world.
consider pytest_addsyspath hook
-----------------------------------------
tags: 2.3
tags:
py.test could call a new pytest_addsyspath() in order to systematically
allow manipulation of sys.path and to inhibit it via --no-addsyspath
@@ -237,7 +310,7 @@ and pytest_configure.
show plugin information in test header
----------------------------------------------------------------
tags: feature 2.3
tags: feature
Now that external plugins are becoming more numerous
it would be useful to have external plugins along with
@@ -245,7 +318,7 @@ their versions displayed as a header line.
deprecate global py.test.config usage
----------------------------------------------------------------
tags: feature 2.3
tags: feature
py.test.ensuretemp and py.test.config are probably the last
objects containing global state. Often using them is not
@@ -255,7 +328,7 @@ as others.
remove deprecated bits in collect.py
-------------------------------------------------------------------
tags: feature 2.3
tags: feature
In an effort to further simplify code, review and remove deprecated bits
in collect.py. Probably good:
@@ -264,7 +337,7 @@ in collect.py. Probably good:
implement fslayout decorator
---------------------------------
tags: feature 2.3
tags: feature
Improve the way how tests can work with pre-made examples,
keeping the layout close to the test function:
@@ -278,9 +351,7 @@ keeping the layout close to the test function:
pass
""")
def test_run(pytester, fslayout):
p = fslayout.find("test_*.py")
p = fslayout.findone("test_*.py")
result = pytester.runpytest(p)
assert result.ret == 0
assert result.passed == 1

View File

@@ -1,2 +1,2 @@
#
__version__ = '2.2.2'
__version__ = '2.2.4'

View File

@@ -50,7 +50,7 @@ def pytest_configure(config):
hook = None
if mode == "rewrite":
hook = rewrite.AssertionRewritingHook()
sys.meta_path.append(hook)
sys.meta_path.insert(0, hook)
warn_about_missing_assertion(mode)
config._assertstate = AssertionState(config, mode)
config._assertstate.hook = hook

View File

@@ -1,8 +1,7 @@
import py
import sys, inspect
from compiler import parse, ast, pycodegen
from _pytest.assertion.util import format_explanation
from _pytest.assertion.reinterpret import BuiltinAssertionError
from _pytest.assertion.util import format_explanation, BuiltinAssertionError
passthroughex = py.builtin._sysex

View File

@@ -1,7 +1,6 @@
import sys
import py
BuiltinAssertionError = py.builtin.builtins.AssertionError
from _pytest.assertion.util import BuiltinAssertionError
class AssertionError(BuiltinAssertionError):
def __init__(self, *args):

View File

@@ -1,7 +1,6 @@
"""Rewrite assertion AST to produce nice error messages"""
import ast
import collections
import errno
import itertools
import imp
@@ -298,7 +297,7 @@ binop_map = {
ast.Mult : "*",
ast.Div : "/",
ast.FloorDiv : "//",
ast.Mod : "%",
ast.Mod : "%%", # escaped for string formatting
ast.Eq : "==",
ast.NotEq : "!=",
ast.Lt : "<",

View File

@@ -2,6 +2,7 @@
import py
BuiltinAssertionError = py.builtin.builtins.AssertionError
# The _reprcompare attribute on the util module is used by the new assertion
# interpretation code and assertion rewriter to detect this plugin was

View File

@@ -321,13 +321,15 @@ def importplugin(importspec):
name = importspec
try:
mod = "_pytest." + name
return __import__(mod, None, None, '__doc__')
__import__(mod)
return sys.modules[mod]
except ImportError:
#e = py.std.sys.exc_info()[1]
#if str(e).find(name) == -1:
# raise
pass #
return __import__(importspec, None, None, '__doc__')
__import__(importspec)
return sys.modules[importspec]
class MultiCall:
""" execute a call into multiple python functions/methods. """
@@ -463,13 +465,8 @@ def main(args=None, plugins=None):
""" returned exit code integer, after an in-process testing run
with the given command line arguments, preloading an optional list
of passed in plugin objects. """
try:
config = _prepareconfig(args, plugins)
exitstatus = config.hook.pytest_cmdline_main(config=config)
except UsageError:
e = sys.exc_info()[1]
sys.stderr.write("ERROR: %s\n" %(e.args[0],))
exitstatus = 3
config = _prepareconfig(args, plugins)
exitstatus = config.hook.pytest_cmdline_main(config=config)
return exitstatus
class UsageError(Exception):

View File

@@ -34,15 +34,21 @@ class Junit(py.xml.Namespace):
# this dynamically instead of hardcoding it. The spec range of valid
# chars is: Char ::= #x9 | #xA | #xD | [#x20-#xD7FF] | [#xE000-#xFFFD]
# | [#x10000-#x10FFFF]
_illegal_unichrs = [(0x00, 0x08), (0x0B, 0x0C), (0x0E, 0x19),
(0xD800, 0xDFFF), (0xFDD0, 0xFFFF)]
_illegal_ranges = [unicode("%s-%s") % (unichr(low), unichr(high))
for (low, high) in _illegal_unichrs
_legal_chars = (0x09, 0x0A, 0x0d)
_legal_ranges = (
(0x20, 0xD7FF),
(0xE000, 0xFFFD),
(0x10000, 0x10FFFF),
)
_legal_xml_re = [unicode("%s-%s") % (unichr(low), unichr(high))
for (low, high) in _legal_ranges
if low < sys.maxunicode]
illegal_xml_re = re.compile(unicode('[%s]') %
unicode('').join(_illegal_ranges))
del _illegal_unichrs
del _illegal_ranges
_legal_xml_re = [unichr(x) for x in _legal_chars] + _legal_xml_re
illegal_xml_re = re.compile(unicode('[^%s]') %
unicode('').join(_legal_xml_re))
del _legal_chars
del _legal_ranges
del _legal_xml_re
def bin_xml_escape(arg):
def repl(matchobj):
@@ -75,6 +81,11 @@ def pytest_unconfigure(config):
config.pluginmanager.unregister(xml)
def mangle_testnames(names):
names = [x.replace(".py", "") for x in names if x != '()']
names[0] = names[0].replace("/", '.')
return names
class LogXML(object):
def __init__(self, logfile, prefix):
logfile = os.path.expanduser(os.path.expandvars(logfile))
@@ -85,9 +96,7 @@ class LogXML(object):
self.failed = self.errors = 0
def _opentestcase(self, report):
names = report.nodeid.split("::")
names[0] = names[0].replace("/", '.')
names = [x.replace(".py", "") for x in names if x != "()"]
names = mangle_testnames(report.nodeid.split("::"))
classnames = names[:-1]
if self.prefix:
classnames.insert(0, self.prefix)

View File

@@ -10,6 +10,7 @@ EXIT_OK = 0
EXIT_TESTSFAILED = 1
EXIT_INTERRUPTED = 2
EXIT_INTERNALERROR = 3
EXIT_USAGEERROR = 4
name_re = py.std.re.compile("^[a-zA-Z_]\w*$")
@@ -65,30 +66,34 @@ def wrap_session(config, doit):
session.exitstatus = EXIT_OK
initstate = 0
try:
config.pluginmanager.do_configure(config)
initstate = 1
config.hook.pytest_sessionstart(session=session)
initstate = 2
doit(config, session)
except pytest.UsageError:
raise
except KeyboardInterrupt:
excinfo = py.code.ExceptionInfo()
config.hook.pytest_keyboard_interrupt(excinfo=excinfo)
session.exitstatus = EXIT_INTERRUPTED
except:
excinfo = py.code.ExceptionInfo()
config.pluginmanager.notify_exception(excinfo, config.option)
session.exitstatus = EXIT_INTERNALERROR
if excinfo.errisinstance(SystemExit):
sys.stderr.write("mainloop: caught Spurious SystemExit!\n")
if initstate >= 2:
config.hook.pytest_sessionfinish(session=session,
exitstatus=session.exitstatus or (session._testsfailed and 1))
if not session.exitstatus and session._testsfailed:
session.exitstatus = EXIT_TESTSFAILED
if initstate >= 1:
config.pluginmanager.do_unconfigure(config)
try:
config.pluginmanager.do_configure(config)
initstate = 1
config.hook.pytest_sessionstart(session=session)
initstate = 2
doit(config, session)
except pytest.UsageError:
msg = sys.exc_info()[1].args[0]
sys.stderr.write("ERROR: %s\n" %(msg,))
session.exitstatus = EXIT_USAGEERROR
except KeyboardInterrupt:
excinfo = py.code.ExceptionInfo()
config.hook.pytest_keyboard_interrupt(excinfo=excinfo)
session.exitstatus = EXIT_INTERRUPTED
except:
excinfo = py.code.ExceptionInfo()
config.pluginmanager.notify_exception(excinfo, config.option)
session.exitstatus = EXIT_INTERNALERROR
if excinfo.errisinstance(SystemExit):
sys.stderr.write("mainloop: caught Spurious SystemExit!\n")
finally:
if initstate >= 2:
config.hook.pytest_sessionfinish(session=session,
exitstatus=session.exitstatus or (session._testsfailed and 1))
if not session.exitstatus and session._testsfailed:
session.exitstatus = EXIT_TESTSFAILED
if initstate >= 1:
config.pluginmanager.do_unconfigure(config)
return session.exitstatus
def pytest_cmdline_main(config):

View File

@@ -2,7 +2,7 @@
import py, sys
class url:
base = "http://paste.pocoo.org"
base = "http://bpaste.net"
xmlrpc = base + "/xmlrpc/"
show = base + "/show/"
@@ -11,7 +11,7 @@ def pytest_addoption(parser):
group._addoption('--pastebin', metavar="mode",
action='store', dest="pastebin", default=None,
type="choice", choices=['failed', 'all'],
help="send failed|all info to Pocoo pastebin service.")
help="send failed|all info to bpaste.net pastebin service.")
def pytest_configure(__multicall__, config):
import tempfile

View File

@@ -311,12 +311,14 @@ class Class(PyCollectorMixin, pytest.Collector):
setup_class = getattr(self.obj, 'setup_class', None)
if setup_class is not None:
setup_class = getattr(setup_class, 'im_func', setup_class)
setup_class = getattr(setup_class, '__func__', setup_class)
setup_class(self.obj)
def teardown(self):
teardown_class = getattr(self.obj, 'teardown_class', None)
if teardown_class is not None:
teardown_class = getattr(teardown_class, 'im_func', teardown_class)
teardown_class = getattr(teardown_class, '__func__', teardown_class)
teardown_class(self.obj)
class Instance(PyCollectorMixin, pytest.Collector):

View File

@@ -416,9 +416,10 @@ def importorskip(modname, minversion=None):
__tracebackhide__ = True
compile(modname, '', 'eval') # to catch syntaxerrors
try:
mod = __import__(modname, None, None, ['__doc__'])
__import__(modname)
except ImportError:
py.test.skip("could not import %r" %(modname,))
mod = sys.modules[modname]
if minversion is None:
return mod
verattr = getattr(mod, '__version__', None)

View File

@@ -132,6 +132,14 @@ def check_xfail_no_run(item):
def pytest_runtest_makereport(__multicall__, item, call):
if not isinstance(item, pytest.Function):
return
# unitttest special case, see setting of _unexpectedsuccess
if hasattr(item, '_unexpectedsuccess'):
rep = __multicall__.execute()
if rep.when == "call":
# we need to translate into how py.test encodes xpass
rep.keywords['xfail'] = "reason: " + repr(item._unexpectedsuccess)
rep.outcome = "failed"
return rep
if not (call.excinfo and
call.excinfo.errisinstance(py.test.xfail.Exception)):
evalxfail = getattr(item, '_evalxfail', None)

View File

@@ -91,22 +91,28 @@ class TestCaseFunction(pytest.Function):
self._addexcinfo(rawexcinfo)
def addFailure(self, testcase, rawexcinfo):
self._addexcinfo(rawexcinfo)
def addSkip(self, testcase, reason):
try:
pytest.skip(reason)
except pytest.skip.Exception:
self._addexcinfo(sys.exc_info())
def addExpectedFailure(self, testcase, rawexcinfo, reason):
def addExpectedFailure(self, testcase, rawexcinfo, reason=""):
try:
pytest.xfail(str(reason))
except pytest.xfail.Exception:
self._addexcinfo(sys.exc_info())
def addUnexpectedSuccess(self, testcase, reason):
pass
def addUnexpectedSuccess(self, testcase, reason=""):
self._unexpectedsuccess = reason
def addSuccess(self, testcase):
pass
def stopTest(self, testcase):
pass
def runtest(self):
self._testcase(result=self)

View File

@@ -46,7 +46,7 @@ except ImportError:
args = [quote(arg) for arg in args]
return os.spawnl(os.P_WAIT, sys.executable, *args) == 0
DEFAULT_VERSION = "0.6.24"
DEFAULT_VERSION = "0.6.27"
DEFAULT_URL = "http://pypi.python.org/packages/source/d/distribute/"
SETUPTOOLS_FAKED_VERSION = "0.6c11"
@@ -63,7 +63,7 @@ Description: xxx
""" % SETUPTOOLS_FAKED_VERSION
def _install(tarball):
def _install(tarball, install_args=()):
# extracting the tarball
tmpdir = tempfile.mkdtemp()
log.warn('Extracting in %s', tmpdir)
@@ -81,7 +81,7 @@ def _install(tarball):
# installing
log.warn('Installing Distribute')
if not _python_cmd('setup.py', 'install'):
if not _python_cmd('setup.py', 'install', *install_args):
log.warn('Something went wrong during the installation.')
log.warn('See the error message above.')
finally:
@@ -306,6 +306,9 @@ def _create_fake_setuptools_pkg_info(placeholder):
log.warn('%s already exists', pkg_info)
return
if not os.access(pkg_info, os.W_OK):
log.warn("Don't have permissions to write %s, skipping", pkg_info)
log.warn('Creating %s', pkg_info)
f = open(pkg_info, 'w')
try:
@@ -474,11 +477,20 @@ def _extractall(self, path=".", members=None):
else:
self._dbg(1, "tarfile: %s" % e)
def _build_install_args(argv):
install_args = []
user_install = '--user' in argv
if user_install and sys.version_info < (2,6):
log.warn("--user requires Python 2.6 or later")
raise SystemExit(1)
if user_install:
install_args.append('--user')
return install_args
def main(argv, version=DEFAULT_VERSION):
"""Install or upgrade setuptools and EasyInstall"""
tarball = download_setuptools()
_install(tarball)
_install(tarball, _build_install_args(argv))
if __name__ == '__main__':

View File

@@ -1,9 +1,10 @@
pytest-2.2.2: bug fixes
===========================================================================
pytest-2.2.2 is a minor backward-compatible release of the versatile py.test
testing tool. It contains bug fixes and a few refinements particularly
to reporting with "--collectonly", see below for betails.
pytest-2.2.2 (updated to 2.2.3 to fix packaging issues) is a minor
backward-compatible release of the versatile py.test testing tool. It
contains bug fixes and a few refinements particularly to reporting with
"--collectonly", see below for betails.
For general information see here:

View File

@@ -0,0 +1,39 @@
pytest-2.2.4: bug fixes, better junitxml/unittest/python3 compat
===========================================================================
pytest-2.2.4 is a minor backward-compatible release of the versatile
py.test testing tool. It contains bug fixes and a few refinements
to junitxml reporting, better unittest- and python3 compatibility.
For general information see here:
http://pytest.org/
To install or upgrade pytest:
pip install -U pytest # or
easy_install -U pytest
Special thanks for helping on this release to Ronny Pfannschmidt
and Benjamin Peterson and the contributors of issues.
best,
holger krekel
Changes between 2.2.3 and 2.2.4
-----------------------------------
- fix error message for rewritten assertions involving the % operator
- fix issue 126: correctly match all invalid xml characters for junitxml
binary escape
- fix issue with unittest: now @unittest.expectedFailure markers should
be processed correctly (you can also use @pytest.mark markers)
- document integration with the extended distribute/setuptools test commands
- fix issue 140: propperly get the real functions
of bound classmethods for setup/teardown_class
- fix issue #141: switch from the deceased paste.pocoo.org to bpaste.net
- fix issue #143: call unconfigure/sessionfinish always when
configure/sessionstart where called
- fix issue #144: better mangle test ids to junitxml classnames
- upgrade distribute_setup.py to 0.6.27

View File

@@ -94,6 +94,40 @@ options.
.. _`test discovery`:
.. _`Python test discovery`:
Integration with setuptools/distribute test commands
----------------------------------------------------
Distribute/Setuptools support test requirements,
which means its really easy to extend its test command
to support running a pytest from test requirements::
from setuptools.command.test import test as TestCommand
class PyTest(TestCommand):
def finalize_options(self):
TestCommand.finalize_options(self)
self.test_args = []
self.test_suite = True
def run_tests(self):
#import here, cause outside the eggs aren't loaded
import pytest
pytest.main(self.test_args)
setup(
#...,
tests_require=['pytest'],
cmdclass = {'test': pytest},
)
Now if you run::
python setup.py test
this will download py.test if needed and then run py.test
as you would expect it to.
Conventions for Python test discovery
-------------------------------------------------

View File

@@ -36,7 +36,7 @@ Stopping after the first (or N) failures
To stop the testing process after the first (N) failures::
py.test -x # stop after first failure
py.test -maxfail=2 # stop after two failures
py.test --maxfail=2 # stop after two failures
Specifying tests / selecting tests
---------------------------------------------------
@@ -70,7 +70,7 @@ Dropping to PDB (Python Debugger) on failures
.. _PDB: http://docs.python.org/library/pdb.html
Python comes with a builtin Python debugger called PDB_. ``py.test``
allows to drop into the PDB prompt via a command line option::
allows one to drop into the PDB prompt via a command line option::
py.test --pdb

View File

@@ -24,7 +24,7 @@ def main():
name='pytest',
description='py.test: simple powerful testing with Python',
long_description = long_description,
version='2.2.2',
version='2.2.4',
url='http://pytest.org',
license='MIT license',
platforms=['unix', 'linux', 'osx', 'cygwin', 'win32'],
@@ -32,7 +32,7 @@ def main():
author_email='holger at merlinux.eu',
entry_points= make_entry_points(),
# the following should be enabled for release
install_requires=['py>=1.4.7.dev2'],
install_requires=['py>=1.4.8'],
classifiers=['Development Status :: 6 - Mature',
'Intended Audience :: Developers',
'License :: OSI Approved :: MIT License',

View File

@@ -57,6 +57,22 @@ class TestGeneralUsage:
assert result.ret != 0
result.stderr.fnmatch_lines(["ERROR: file not found*asd"])
def test_file_not_found_unconfigure_issue143(self, testdir):
testdir.makeconftest("""
def pytest_configure():
print("---configure")
def pytest_unconfigure():
print("---unconfigure")
""")
result = testdir.runpytest("-s", "asd")
assert result.ret == 4 # EXIT_USAGEERROR
result.stderr.fnmatch_lines(["ERROR: file not found*asd"])
s = result.stdout.fnmatch_lines([
"*---configure",
"*---unconfigure",
])
def test_config_preparse_plugin_option(self, testdir):
testdir.makepyfile(pytest_xyz="""
def pytest_addoption(parser):
@@ -475,11 +491,11 @@ class TestDurations:
import time
frag = 0.02
def test_2():
time.sleep(frag*2)
time.sleep(frag*5)
def test_1():
time.sleep(frag)
def test_3():
time.sleep(frag*3)
time.sleep(frag*10)
"""
def test_calls(self, testdir):

View File

@@ -322,3 +322,18 @@ def test_assert_raises_in_nonzero_of_object_pytest_issue10():
e = exvalue()
s = str(e)
assert "<MY42 object> < 0" in s
@py.test.mark.skipif("sys.version_info >= (2,6)")
def test_oldinterpret_importation():
# we had a cyclic import there
# requires pytest on sys.path
res = py.std.subprocess.call([
py.std.sys.executable, '-c', str(py.code.Source("""
try:
from _pytest.assertion.newinterpret import interpret
except ImportError:
from _pytest.assertion.oldinterpret import interpret
"""))
])
assert res == 0

View File

@@ -195,6 +195,10 @@ class TestAssertionRewrite:
y = -1
assert x + y
assert getmsg(f) == "assert (1 + -1)"
def f():
x = range(10)
assert not 5 % 4
assert getmsg(f) == "assert not (5 % 4)"
def test_call(self):
def g(a=42, *args, **kwargs):
@@ -346,6 +350,7 @@ def test_no_bytecode():
monkeypatch.setenv("PYTHONDONTWRITEBYTECODE", "1")
assert testdir.runpytest().ret == 0
@pytest.mark.skipif('"__pypy__" in sys.modules')
def test_pyc_vs_pyo(self, testdir, monkeypatch):
testdir.makepyfile("""
import pytest

View File

@@ -279,6 +279,13 @@ class TestPython:
if not sys.platform.startswith("java"):
assert "hx" in fnode.toxml()
def test_mangle_testnames():
from _pytest.junitxml import mangle_testnames
names = ["a/pything.py", "Class", "()", "method"]
newnames = mangle_testnames(names)
assert newnames == ["a.pything", "Class", "method"]
class TestNonPython:
def test_summing_simple(self, testdir):
testdir.makeconftest("""
@@ -340,7 +347,7 @@ def test_nullbyte_replace(testdir):
assert '#x0' in text
def test_invalid_xml_escape(testdir):
def test_invalid_xml_escape():
# Test some more invalid xml chars, the full range should be
# tested really but let's just thest the edges of the ranges
# intead.
@@ -355,27 +362,23 @@ def test_invalid_xml_escape(testdir):
except NameError:
unichr = chr
u = py.builtin._totext
invalid = (0x1, 0xB, 0xC, 0xE, 0x19,)
# 0xD800, 0xDFFF, 0xFFFE, 0x0FFFF) #, 0x110000)
invalid = (0x00, 0x1, 0xB, 0xC, 0xE, 0x19,
27, # issue #126
0xD800, 0xDFFF, 0xFFFE, 0x0FFFF) #, 0x110000)
valid = (0x9, 0xA, 0x20,) # 0xD, 0xD7FF, 0xE000, 0xFFFD, 0x10000, 0x10FFFF)
all = invalid + valid
prints = [u(" sys.stdout.write('''0x%X-->%s<--''')") % (i, unichr(i))
for i in all]
testdir.makepyfile(u("# -*- coding: UTF-8 -*-"),
u("import sys"),
u("def test_print_bytes():"),
u("\n").join(prints),
u(" assert False"))
xmlf = testdir.tmpdir.join('junit.xml')
result = testdir.runpytest('--junitxml=%s' % xmlf)
text = xmlf.read()
from _pytest.junitxml import bin_xml_escape
for i in invalid:
got = bin_xml_escape(unichr(i))
if i <= 0xFF:
assert '#x%02X' % i in text
expected = '#x%02X' % i
else:
assert '#x%04X' % i in text
expected = '#x%04X' % i
assert got == expected
for i in valid:
assert chr(i) in text
assert chr(i) == bin_xml_escape(unichr(i))
def test_logxml_path_expansion():
from _pytest.junitxml import LogXML

View File

@@ -56,6 +56,24 @@ class TestClass:
"*collected 0*",
])
def test_setup_teardown_class_as_classmethod(self, testdir):
testdir.makepyfile("""
class TestClassMethod:
@classmethod
def setup_class(cls):
pass
def test_1(self):
pass
@classmethod
def teardown_class(cls):
pass
""")
result = testdir.runpytest()
result.stdout.fnmatch_lines([
"*1 passed*",
])
class TestGenerator:
def test_generative_functions(self, testdir):
modcol = testdir.getmodulecol("""

View File

@@ -262,7 +262,7 @@ class TestCollectonly:
not to have the items attribute
"""
result = testdir.runpytest("--collectonly", "uhm_missing_path")
assert result.ret == 3
assert result.ret == 4
result.stderr.fnmatch_lines([
'*ERROR: file not found*',
])

View File

@@ -459,3 +459,24 @@ def test_unittest_typerror_traceback(testdir):
result = testdir.runpytest()
assert "TypeError" in result.stdout.str()
assert result.ret == 1
@pytest.mark.skipif("sys.version_info < (2,7)")
def test_unittest_unexpected_failure(testdir):
testdir.makepyfile("""
import unittest
class MyTestCase(unittest.TestCase):
@unittest.expectedFailure
def test_func1(self):
assert 0
@unittest.expectedFailure
def test_func2(self):
assert 1
""")
result = testdir.runpytest("-rxX")
result.stdout.fnmatch_lines([
"*XFAIL*MyTestCase*test_func1*",
"*XPASS*MyTestCase*test_func2*",
"*1 xfailed*1 xpass*",
])