Test & Code in Python

Topics include automated testing, testing strategy, software engineering practices, packaging, Python, pytest, data science, TDD, continuous integration, and software methodologies. Also anything I think helps make the daily life of a software developer more fun and rewarding. Hosted by Brian Okken.

https://testandcode.com

subscribe
share





episode 166: unittest expectedFailure and xfail


xfail isn't just for pytest tests. Python's unittest has @unittest.expectedFailure.

In this episode, we cover:

  • using @unittest.expectedFailure
  • the results of passing and failing tests with expectedFailure
  • using pytest as a test runner for unittest
  • using pytest markers on unittest tests

Docs for expectedFailure:
https://docs.python.org/3/library/unittest.html#skipping-tests-and-expected-failures

Some 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")

Sponsored By:

  • Patreon Supporters: Help support the show with as little as $1 per month and be the first to know when new episodes come out.

Support Test & Code in Python


share







 2021-10-14  6m