Test & Code

166: unittest expectedFailure and xfail


Listen Later

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






...more
View all episodesView all episodes
Download on the App Store

Test & CodeBy Brian Okken

  • 4.7
  • 4.7
  • 4.7
  • 4.7
  • 4.7

4.7

70 ratings


More shows like Test & Code

View all
Radiolab by WNYC Studios

Radiolab

44,010 Listeners

Software Engineering Daily by Software Engineering Daily

Software Engineering Daily

623 Listeners

Heavy Networking by Packet Pushers

Heavy Networking

328 Listeners

Talk Python To Me by Michael Kennedy

Talk Python To Me

587 Listeners

Python Bytes by Michael Kennedy and Brian Okken

Python Bytes

214 Listeners

Darknet Diaries by Jack Rhysider

Darknet Diaries

8,001 Listeners

The Real Python Podcast by Real Python

The Real Python Podcast

141 Listeners

Unexplainable by Vox

Unexplainable

2,285 Listeners

Network Automation Nerds by Packet Pushers

Network Automation Nerds

3 Listeners