Replace deprecated load_module
with exec_module
#498
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Closes #494
This was a bit of a nightmare! 😬 this implementation is by no means perfect and it took a great deal of trial and error as well as at least a few days off my lifespan!
A brief summary of what I've done and how I got here (not all of this is in the PR commit history):
load_module
suggests replacing withexec_module
. However, nox needs the module to be passed around andexec_module
returnsNone
so this was a non-starter.importlib.import_module
as this will return theModuleType
. This appeared to work when using nox at the command line but every test that uses one of the demo noxfiles in thetests/resources/
kept failing with aModuleNotFound
error. I tried various things to fix this such as making theresources
dir a valid package, manually changing directories in the tests, trying to resolve relative to absolute imports etc. All to no avail!This still gave me some grief as mypy wouldn't recognise the
exec_module
method despite its use in the exact same way as the example in the link, so I had to# type ignore
that and I had some difficulty with ensuring coverage. You'll notice a single# pragma: no cover
for one of the guard statements as I just couldn't figure out how to mock it out properly for tests.I think if we could get
importlib.import_module
to work here this would be by far the cleanest solution, but as I said I couldn't get it to pass the tests, it kept importing the project's noxfile, not the ones undertests/resources
which was very weird!