-
-
Notifications
You must be signed in to change notification settings - Fork 402
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: regression in testing individual modules #1529
fix: regression in testing individual modules #1529
Conversation
Using `sopel.tools.target...` in `sopel/test_tools.py` an error because `sopel.tools` does not seem to be aware of `target`. I expect this is because `target.py` requires a class from `sopel.tools` and this would leads to circular imports. Need to `import sopel.tools.target` separately to avoid this. `pytest` tests work fine because it knows of `sopel.tools.target` by that name already from traversing the `rootdir`.
While digging around in here, I decided to test every module manually to see if anything else was awry. This little exception came up:
A separate |
That Appreciate the work, @HumorBaby! When I have a bit more time I'll look at this in more depth myself. These fixes are good for a patch branch (yes, I'd appreciate you rebasing this on |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, so, next steps.
This is a quirk of how Python's imports work. In ipython
, for example, import sopel
works because at runtime, something else has already imported sopel.module
and so that attribute is defined. When running as a standalone file, it's not defined (because nothing has used it yet).
Same for test_tools
: At runtime, or during coverage
(CI) tests, the name sopel.tools.target
has already been imported elsewhere and so the attribute is defined, but it isn't defined in standalone tests.
It might not be reasonable for Sopel, as a project, to just go around trying to force anyone who imports the package sopel
(or one of its subpackages) to always load everything under it. We should just be more careful about importing the correct submodules.
@Exirel Your input would be appreciated, but it's not time-sensitive or anything. This PR for 6.6.x is clearly good to go, and we're just talking future stuff for Sopel 7 at this point. 😸
Any individual test of a Sopel module (either as
python a_module.py
orpytest a_module.py
; even with full path), leads to this exception:Using
sopel.tools.target...
inSopel/test_tools.py
throws an error becausesopel.tools
does not seem to be aware oftarget
. I expect this isbecause
target.py
requires a class fromsopel.tools
and this wouldlead to circular imports. Need to
import sopel.tools.target
separately to avoid this.
pytest
tests work fine because it knows ofsopel.tools.target
bythat name already from traversing the
rootdir
.