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

Fix test failing due to __getattr__ in module #1175

Closed

Conversation

dm-ackerman
Copy link
Contributor

Description

The deprecated_handler() function is called by module level getattr functions. It raised an ImportError when a module wasn't an env. This breaks getattr's behaviour when it is called with a default value. It expects getattr to raise an AttributeError if the attr is not found.

Pytest was apparently updated to call getattr(obj, key, default) for several values of key. The import error isn't caught by getattr, breaking the test.

Changing ImportError to AttributeError fixes this. The missing attribute raises the correct error, which is caught by getattr, which sets the value to the default and everything works as intended.

Type of change

  • Bug fix (non-breaking change which fixes an issue)

Checklist:

  • I have run the pre-commit checks with pre-commit run --all-files (see CONTRIBUTING.md instructions to set it up)
  • I have run pytest -v and no errors are present.
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I solved any possible warnings that pytest -v has generated that are related to my code to the best of my knowledge.
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

The deprecated_handler() function is called by module level __getattr__
functions. It raised an ImportError when a module wasn't an env.
This breaks getattr's behaviour when it is called with a default
value. It expects __getattr__ to raise an AttributeError if the attr
is not found.

Pytest was apparently updated to call getattr(obj, key, default)
for several values of key. The import error isn't caught by getattr,
breaking the test.

Changing ImportError to AttributeError fixes this. The missing
attribute raises the correct error, which is caught by getattr,
which sets the value to the default and everything works as
intended.
@dm-ackerman
Copy link
Contributor Author

Well that's annoying, doc tests fail.

It works locally, but seems the workflow uses a different test command. This appears to be a problem with pytest-markdown-docs being incompatible with version 8 of pytest. A random person posted a fix and I opened an issue with pytest-markdown-docs asking them to add the changes and publish a new version. They were super responsive and looks like they are checking it out now. Hopefully it gets approved and sent out.

I patched pytest-markdown-docs locally and it fixes the error. So I'm optimistic that if they push an update, this test failure will be solved.

@dm-ackerman
Copy link
Contributor Author

The pytest-markdown-docs folks were amazing and got pytestv8 support all sorted out. I upgrade the version and it works locally after correcting some problems it found in docs. Added a PR with those fixes, in addition to these, to hopefully be fully compatible with pytest v8: #1177 Closing this. Use that instead.

@dm-ackerman dm-ackerman closed this Feb 7, 2024
@dm-ackerman dm-ackerman deleted the pytest_import_fix branch May 6, 2024 17:02
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.

1 participant