Skip to content

Latest commit

 

History

History
32 lines (22 loc) · 527 Bytes

PT027.md

File metadata and controls

32 lines (22 loc) · 527 Bytes

PT027

use pytest.raises() instead of unittest-style '{assertion}'

Examples

Bad code:

import unittest

class TestFoo(unittest.TestCase):
    def test_foo(self):
        with self.assertRaises(ValueError):
            raise ValueError('foo')

Good code:

import pytest
import unittest

class TestFoo(unittest.TestCase):
    def test_foo(self):
        with pytest.raises(ValueError):
            raise ValueError('foo')

Rationale

  • to enforce the assertion style recommended by pytest