Source
#
# This file implements a plugin for nose, which monitors the net memory leaked
# and opened file descriptors from a test run. The result are written to
# an XML file. This plugin is just an adaptation of nose's built-in
# XUnit plugin.
#
import nose.plugins.xunit
import traceback
import inspect
import time
import os
import subprocess
import sys
import codecs
def nice_classname(obj):
"""Returns a nice name for class object or class instance.
>>> nice_classname(Exception()) # doctest: +ELLIPSIS
'...Exception'
>>> nice_classname(Exception)
'exceptions.Exception'
"""
if inspect.isclass(obj):
cls_name = obj.__name__
else:
cls_name = obj.__class__.__name__
mod = inspect.getmodule(obj)
if mod:
name = mod.__name__
# jython
if name.startswith('org.python.core.'):
name = name[len('org.python.core.'):]
return "%s.%s" % (name, cls_name)
else:
return cls_name
def write_message(fileleak, memoryleak):
if fileleak != 0:
print "Net file descriptors opened:", fileleak
if memoryleak != 0:
print "Net memory allocated:", memoryleak, "kB"
return "<system-out>\
<measurement><name>Files leaked</name><value>" + str(fileleak) + "</value></measurement>\
<measurement><name>Memory leaked (kB)</name><value>" + str(memoryleak) + "</value></measurement>\
</system-out>"
class MemTest(nose.plugins.xunit.Xunit):
name = "memtest"
def options(self, parser, env):
# Identical to the base class method, except that the command line
# option needs to be called something different
"""Sets additional command line options."""
nose.plugins.base.Plugin.options(self, parser, env)
parser.add_option(
'--memtest-file', action='store',
dest='xunit_file', metavar="FILE",