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

Test error handling in setup.py #1824

Closed
wants to merge 3 commits into from

Conversation

devdanzin
Copy link
Contributor

This PR adds some tests for exception handling in setup.py.

It currently uses direct monkey-patching, please let me know if using mock,patch or some other method would be better/cleaner.

I'd be happy to add or remove some of the testing done, as well as reworking or otherwise polishing this PR.

@@ -27,6 +29,12 @@ def setUp(self) -> None:
# Force the most restrictive interpretation.
self.set_environ('LC_ALL', 'C')

def raise_error(self, error: type[Exception]) -> Callable[[Any], Any]:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like something to use unittest.mock or pytest's monkeypatch for. But see below.

# Do we handle all expected errors?
for ext_error in setup.ext_errors:
with pytest.raises(setup.BuildFailed):
setup.build_ext.build_extension = self.raise_error(ext_error)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These tests are mostly checking that we catch certain errors. I'd be more interested in tests that demonstrated actual failure scenarios and that we handled them well, but that seems harder to do. I'm not sure we need these tests.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, closing. If I figure out a way to construct actual failure scenarios I'll propose another PR with realistic tests. Thanks for taking a look!

@devdanzin devdanzin closed this Jul 29, 2024
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

Successfully merging this pull request may close these issues.

2 participants