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

Revise tests that rely on importlib.reload #1205

Open
matthewfeickert opened this issue Dec 6, 2020 · 0 comments
Open

Revise tests that rely on importlib.reload #1205

matthewfeickert opened this issue Dec 6, 2020 · 0 comments
Labels
contrib Targeting pyhf.contrib and not the core of pyhf follow up help wanted Extra attention is needed / contributions welcome tests pytest

Comments

@matthewfeickert
Copy link
Member

Description

RE: pyhf related Stack Overflow question "How to remove a library with monkeypatch or mock in pytest?" which was used to write tests for missing extra dependencies from the contrib extra, @asottile has warned that

reload() can be kinda iffy -- I'd be careful with it (things which have old references to the old module will live on, sometimes it can introduce new copies of singletons (doubletons? tripletons?)) -- I've tracked down many-a-test-pollution problems to reload()

It would be good to look into if there are more reasonable ways to force the reload of the relevant modules to trigger the import error.

In his video testing optional python dependencies (intermediate) Anthony demos using mock.patch.object to patch the imported dependency in the module where it is imported. I think there was some reason I didn't end up doing this for the PR in which contrib download was added, but I can't remember why (maybe because I wanted a specific import error?) so this is probably a good place to start revisiting the Issue.

This comes up in the context of:

@matthewfeickert matthewfeickert added help wanted Extra attention is needed / contributions welcome follow up tests pytest contrib Targeting pyhf.contrib and not the core of pyhf labels Dec 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contrib Targeting pyhf.contrib and not the core of pyhf follow up help wanted Extra attention is needed / contributions welcome tests pytest
Projects
None yet
Development

No branches or pull requests

1 participant