adapt to new plugin architecture and misc cleanups:
- exit with non-zero value on import errors - remove unused imports - make --twisted-logging a boolean option --HG-- branch : trunk
This commit is contained in:
parent
95c28265a6
commit
a5d42b36d2
|
@ -1,4 +1,6 @@
|
||||||
"""
|
"""
|
||||||
|
Allows to test twisted applications with pytest.
|
||||||
|
|
||||||
Notes: twisted's asynchronous behavior may have influence on the order of test-functions
|
Notes: twisted's asynchronous behavior may have influence on the order of test-functions
|
||||||
|
|
||||||
TODO:
|
TODO:
|
||||||
|
@ -6,22 +8,20 @@ TODO:
|
||||||
+ get test to work
|
+ get test to work
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import os
|
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
import py
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from twisted.internet.defer import Deferred
|
from twisted.internet import reactor, defer
|
||||||
|
from twisted.python import failure, log
|
||||||
except ImportError:
|
except ImportError:
|
||||||
print "To use the twisted option you have to install twisted."
|
print "To use the twisted option you have to install twisted."
|
||||||
sys.exit(0)
|
sys.exit(10)
|
||||||
try:
|
try:
|
||||||
from greenlet import greenlet
|
from greenlet import greenlet
|
||||||
except ImportError:
|
except ImportError:
|
||||||
print "Since pylib 1.0 greenlet are removed and separately packaged: " \
|
print "Since pylib 1.0 greenlet are removed and separately packaged: " \
|
||||||
"http://pypi.python.org/pypi/greenlet"
|
"http://pypi.python.org/pypi/greenlet"
|
||||||
sys.exit(0)
|
sys.exit(10)
|
||||||
|
|
||||||
|
|
||||||
def _start_twisted_logging():
|
def _start_twisted_logging():
|
||||||
|
@ -35,14 +35,11 @@ def _start_twisted_logging():
|
||||||
def flush(self):
|
def flush(self):
|
||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
# sys.stdout will be changed by py.test later.
|
# sys.stdout will be changed by py.test later.
|
||||||
import twisted.python.log
|
log.startLogging(Logger(), setStdout=0)
|
||||||
twisted.python.log.startLogging(Logger(), setStdout=0)
|
|
||||||
|
|
||||||
def _run_twisted(logging=False):
|
def _run_twisted(logging=False):
|
||||||
"""Start twisted mainloop and initialize recursive calling of doit()."""
|
"""Start twisted mainloop and initialize recursive calling of doit()."""
|
||||||
|
|
||||||
from twisted.internet import reactor, defer
|
|
||||||
from twisted.python import log, failure
|
|
||||||
# make twisted copy traceback...
|
# make twisted copy traceback...
|
||||||
failure.Failure.cleanFailure = lambda *args: None
|
failure.Failure.cleanFailure = lambda *args: None
|
||||||
if logging:
|
if logging:
|
||||||
|
@ -70,36 +67,20 @@ def _run_twisted(logging=False):
|
||||||
reactor.callLater(0.0, doit, None)
|
reactor.callLater(0.0, doit, None)
|
||||||
reactor.run()
|
reactor.run()
|
||||||
|
|
||||||
|
def pytest_addoption(parser):
|
||||||
class TwistedPlugin:
|
|
||||||
"""Allows to test twisted applications with pytest."""
|
|
||||||
|
|
||||||
def pytest_addoption(self, parser):
|
|
||||||
#parser.addoption("--twisted", dest="twisted",
|
|
||||||
# help="Allows to test twisted applications with pytest.")
|
|
||||||
|
|
||||||
group = parser.addgroup('twisted options')
|
group = parser.addgroup('twisted options')
|
||||||
group.addoption('-T', action='store_true', default=False,
|
group.addoption('--twisted-logging', action='store_true', default=False,
|
||||||
dest = 'twisted',
|
|
||||||
help="Allows to test twisted applications.")
|
|
||||||
group.addoption('--twisted-logging', action='store', default=False,
|
|
||||||
dest='twisted_logging',
|
dest='twisted_logging',
|
||||||
help="switch on twisted internal logging")
|
help="switch on twisted internal logging")
|
||||||
self.twisted = False
|
|
||||||
|
|
||||||
def pytest_configure(self, config):
|
def pytest_configure(config):
|
||||||
twisted = config.getvalue("twisted")
|
|
||||||
twisted_logging = config.getvalue("twisted_logging")
|
twisted_logging = config.getvalue("twisted_logging")
|
||||||
if twisted:
|
|
||||||
self.twisted = True
|
|
||||||
gr_twisted.switch(twisted_logging)
|
gr_twisted.switch(twisted_logging)
|
||||||
|
|
||||||
def pytest_unconfigure(self, config):
|
def pytest_unconfigure(config):
|
||||||
if self.twisted:
|
|
||||||
gr_twisted.switch(None)
|
gr_twisted.switch(None)
|
||||||
|
|
||||||
def pytest_pyfunc_call(self, pyfuncitem, *args, **kwargs):
|
def pytest_pyfunc_call(pyfuncitem, *args, **kwargs):
|
||||||
if self.twisted:
|
|
||||||
args = args or pyfuncitem._args # generator tests
|
args = args or pyfuncitem._args # generator tests
|
||||||
# XXX1 kwargs?
|
# XXX1 kwargs?
|
||||||
# XXX2 we want to delegate actual call to next plugin
|
# XXX2 we want to delegate actual call to next plugin
|
||||||
|
|
Loading…
Reference in New Issue