-
Notifications
You must be signed in to change notification settings - Fork 1
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
Modify load_feature_tables() function to be also used in a Notebook setting #58
base: develop
Are you sure you want to change the base?
Conversation
I was running into issues with __file__ in a Jupyter notebook. I found that the issue was happening because typically __file__ is defined in a script or module setting, but not in a notebook. Also added a unit test.
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.
Can you show me an example of where the current code doesn't work?
) | ||
except NameError: | ||
# If __file__ is not available (i.e. Jupyter notebook), use the current working directory | ||
pkg_root_dir = pathlib.Path(os.getcwd()) |
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.
pkg_root_dir = pathlib.Path(os.getcwd()) | |
pkg_root_dir = pathlib.Path.cwd() |
if p.parts[-1] == "student_success_tool" | ||
) | ||
except NameError: | ||
# If __file__ is not available (i.e. Jupyter notebook), use the current working directory |
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.
I'm very surprised by this! I thought __file__
refers to the path to this module, no matter the env in which it's being imported. In fact I don't believe I've ever had this issue in a Notebook.
if toml_content: | ||
toml_file = tmpdir.join("features_table.toml") | ||
toml_file.write(toml_content) | ||
|
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.
nit: remove whitespace line
if expect_exception: | ||
with pytest.raises(expect_exception): | ||
utils.load_features_table(file_path) |
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.
In the case of "no error", standard practice is to use from contextlib import nullcontext as does_not_raise
then with pytest.raises(does_not_raise)
works in the same manner as an exception. You can find a couple examples of this pattern in other unit tests.
I was running into issues with
__file__
in a Jupyter notebook. I found that the issue was happening because typically__file__
is defined in a script or module setting, but not in a notebook. Also added a unit test.changes
context
__file__
is not defined".questions
None