-
Notifications
You must be signed in to change notification settings - Fork 515
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
Set pytest import mode to importlib #460
Conversation
✅ Deploy Preview for torchtune-preview ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
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.
You're amazing
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.
Awesome investigation and thanks for the thorough explanation!
Very noob q: should we try to get test_configs
actual unittest working + running in CI, instead of deleting it? Seems quite valuable to ensure all our checked in configs are well formed.
@rohan-varma this is a very reasonable question. I am going to punt that to another change, mainly because (a) the test is already being skipped, (b) @RdoubleA has other config changes inflight (see #456), and (c) I claim having a well-functioning CI trumps any individual unit test. But I’ve created #466 for this. |
Context
#445 broke tune cli. Ref:
However, neither local runs of pytest nor our CI caught this import error.
This is because of some default pytest behavior modifying
sys.path
. Deep in pytest internals, theimport_path
method is called here to import any modules necessary to accessconftest.py
. Note that the default value of theimportmode
variable here isImportMode.prepend
(different import modes are explained here). The upshot is that here the variablepkg_root
gets prepended tosys.path
. I inspected this variable in my local pytest run, and it is in fact/data/users/ebs/torchtune
(i.e. the package root).Why is this bad? Well now that recipes are not importable, appending the package root to
sys.path
before running pytest is bad. Because it means pytest will always be able to find stuff inrecipes/
, even though it shouldn't.Changelog
pyproject.toml
file to override theprepend
import behavior withimportlib
. (Maybe obviously) this usesimportlib
instead and does not touchsys.path
.Test plan
We actually still have some erroneous recipes imports floating around (e.g. here in
test_configs.py
)I locally ran
Prior to modifying
test_configs.py
we can now see the import error in our CI (link to failed job):After 0174701,
test_configs.py
is removed, and CI should (hopefully) be green.Fixes #459