166: unittest expectedFailure and xfail - podcast episode cover

166: unittest expectedFailure and xfail

Oct 14, 20217 minSeason 1Ep. 166
--:--
--:--
Download Metacast podcast app
Listen to this episode in Metacast mobile app
Don't just listen to podcasts. Learn from them with transcripts, summaries, and chapters for every episode. Skim, search, and bookmark insights. Learn more

Episode description

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




Help support the show AND learn pytest: 

  • The Complete pytest course is now a bundle, with each part available separately.
  • Whether you need to get started with pytest today, or want to power up your pytest skills, PythonTest has a course for you.

★ Support this podcast on Patreon ★
For the best experience, listen in Metacast app for iOS or Android
Open in Metacast
166: unittest expectedFailure and xfail | Test & Code podcast - Listen or read transcript on Metacast