[TIP] py.test and unittest2 expectedFailure decorator
holger krekel
holger at merlinux.eu
Mon Mar 19 22:58:39 PDT 2012
Hi David,
it's a bug in py.test. Now fixed in the dev repo. You can install with:
pip install -i http://pypi.testrun.org -U pytest
and should get --version >= 2.2.4.dev2.
Two notes that might be interesting to you:
* you can pass "-rxX" options to see more info on unexpected failure marked
tests. You can add those permanently to your ini-file, see
http://pytest.org/latest/customize.html#adding-default-options
* you can also use @pytest.mark.xfail on unittest test functions or classes
or modules - it has a few more options than unittest does, see:
http://pytest.org/latest/skipping.html#mark-a-test-function-as-expected-to-fail
have fun,
holger
On Mon, Mar 19, 2012 at 14:02 -0500, David Cournapeau wrote:
> Hi there,
>
> I'd like to be able to use expectedFailure from
> unittest2/unittest at python2.7with py.test. For a test like:
>
> import unittest
>
> class Foo(unittest.TestCase):
> @unittest.expectedFailure
> def test_working(self):
> "A working test that is expected to fail"
>
> I get the traceback:
>
> self = <foo.Foo testMethod=test_working>, result = <TestCaseFunction
> 'test_working'>
>
> def run(self, result=None):
> orig_result = result
> if result is None:
> result = self.defaultTestResult()
> startTestRun = getattr(result, 'startTestRun', None)
> if startTestRun is not None:
> startTestRun()
>
> self._resultForDoCleanups = result
> result.startTest(self)
>
> testMethod = getattr(self, self._testMethodName)
> if (getattr(self.__class__, "__unittest_skip__", False) or
> getattr(testMethod, "__unittest_skip__", False)):
> # If the class or method was skipped.
> try:
> skip_why = (getattr(self.__class__,
> '__unittest_skip_why__', '')
> or getattr(testMethod, '__unittest_skip_why__',
> ''))
> self._addSkip(result, skip_why)
> finally:
> result.stopTest(self)
> return
> try:
> success = False
> try:
> self.setUp()
> except SkipTest as e:
> self._addSkip(result, str(e))
> except KeyboardInterrupt:
> raise
> except:
> result.addError(self, sys.exc_info())
> else:
> try:
> testMethod()
> except KeyboardInterrupt:
> raise
> except self.failureException:
> result.addFailure(self, sys.exc_info())
> except _ExpectedFailure as e:
> addExpectedFailure = getattr(result,
> 'addExpectedFailure', None)
> if addExpectedFailure is not None:
> addExpectedFailure(self, e.exc_info)
> else:
> warnings.warn("TestResult has no addExpectedFailure
> method, reporting as passes",
> RuntimeWarning)
> result.addSuccess(self)
> except _UnexpectedSuccess:
> addUnexpectedSuccess = getattr(result,
> 'addUnexpectedSuccess', None)
> if addUnexpectedSuccess is not None:
> > addUnexpectedSuccess(self)
> E TypeError: addUnexpectedSuccess() takes exactly 3
> arguments (2 given)
>
> Is it a but or am I using it wrong ?
>
> cheers,
>
> David
> _______________________________________________
> testing-in-python mailing list
> testing-in-python at lists.idyll.org
> http://lists.idyll.org/listinfo/testing-in-python
More information about the testing-in-python
mailing list