-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Closed
Labels
bugSomething isn't workingSomething isn't workinghelp wantedContributions especially welcomeContributions especially welcome
Description
from unittest import TestCase, main
class TestFoo(TestCase):
def test_foo(self):
with self.assertRaises(Exception) as exc:
raise Exception('foo')
assert str(exc.exception) == 'foo'
main()gets converted by ruff --fix --select PT027 --unsafe-fixes foo.py into:
from unittest import TestCase, main
import pytest
class TestFoo(TestCase):
def test_foo(self):
with pytest.raises(Exception) as exc:
raise Exception('foo')
assert str(exc.exception) == 'foo'
main()causing:
E
======================================================================
ERROR: test_foo (__main__.TestFoo)
----------------------------------------------------------------------
Traceback (most recent call last):
File "foo.py", line 10, in test_foo
assert str(exc.exception) == 'foo'
AttributeError: 'ExceptionInfo' object has no attribute 'exception'
----------------------------------------------------------------------
Ran 1 test in 0.000s
FAILED (errors=1)
correct would be:
from unittest import TestCase, main
import pytest
class TestFoo(TestCase):
def test_foo(self):
with pytest.raises(Exception) as exc:
raise Exception('foo')
assert str(exc.value) == 'foo'
main()Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't workinghelp wantedContributions especially welcomeContributions especially welcome