166: unittest expectedFailure and xfail

14/10/2021 6 min Episodio 166
166: unittest expectedFailure and xfail

Listen "166: unittest expectedFailure and xfail"

Episode Synopsis


xfail isn't just for pytest tests. Python's unittest has @unittest.expectedFailure.In this episode, we cover:using @unittest.expectedFailurethe results of passing and failing tests with expectedFailureusing pytest as a test runner for unittestusing pytest markers on unittest testsDocs for expectedFailure:  https://docs.python.org/3/library/unittest.html#skipping-tests-and-expected-failuresSome sample code.  unittest only:import unittest

class ExpectedFailureTestCase(unittest.TestCase):

@unittest.expectedFailure
def test_fail(self):
self.assertEqual(1, 0, "broken")

@unittest.expectedFailure
def test_pass(self):
self.assertEqual(1, 1, "not broken")
unittest with pytest markers:import unittest
import pytest


class ExpectedFailureTestCase(unittest.TestCase):

@pytest.mark.xfail
def test_fail(self):
self.assertEqual(1, 0, "broken")

@pytest.mark.xfail
def test_pass(self):
self.assertEqual(1, 1, "not broken")