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

more concise tests with pytest.raises #276

Open
shimwell opened this issue Nov 8, 2022 · 0 comments
Open

more concise tests with pytest.raises #276

shimwell opened this issue Nov 8, 2022 · 0 comments

Comments

@shimwell
Copy link
Member

shimwell commented Nov 8, 2022

We have lots of tests that have a nested function def and then assert the function call raises an error, for example

def test_graveyard_error_when_no_offset_or_size(self):
"""Attempts to make a shape with a graveyard_size that is an int
which should raise a ValueError"""
def incorrect_graveyard():
test_shape = paramak.RotateStraightShape(
points=[(0, 0), (0, 20), (20, 20)],
graveyard_size=None,
graveyard_offset=None,
)
test_shape.make_graveyard()
self.assertRaises(ValueError, incorrect_graveyard)

however this test could be shortened to by using pytest.raises

def test_graveyard_error_when_no_offset_or_size(self):
    """Attempts to make a shape with a graveyard_size that is an int
    which should raise a ValueError"""

    with pytest.raises(ValueError):
        test_shape = paramak.RotateStraightShape(
            points=[(0, 0), (0, 20), (20, 20)],
            graveyard_size=None,
            graveyard_offset=None,
        )
        test_shape.make_graveyard()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant