Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

assertRaises used as an expression is converted to a statement, resulting in a syntax error #25

Open
jdufresne opened this issue Jan 12, 2019 · 1 comment
Labels

Comments

@jdufresne
Copy link
Contributor

jdufresne commented Jan 12, 2019

Example input:

class MyTest(unittest.TestCase):
    def test_thing(self):
        self.my_custom_assert(self.assertRaises(IOError, my_func))

Output

@@ -1,3 +1,5 @@
+import pytest
 class MyTest(unittest.TestCase):
     def test_thing(self):
-        self.my_custom_assert(self.assertRaises(IOError, my_func))
+        self.my_custom_assert(with pytest.raises(IOError):
+            my_func())

There is now a with statement as the first argument passed to my_custom_assert. pytest.raises also supports an expression syntax, so perhaps that should be used here as well.

This came up in a real life project:

https://github.com/python-pillow/Pillow/blob/7bf5246b93cc89cfb9d6cca78c4719a943b10585/Tests/test_file_webp.py#L20

@htgoebel
Copy link
Collaborator

This should be easy to fiy by adding here a test whether the current nodes parent node is an expression - or something like this.

We's apprechiae a pull-request. Please mind adding a test-case, too. Thanks.

@htgoebel htgoebel added the bug label May 27, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants