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

[Bug]: ModuleNotFoundError: No module named 'pytest' #535

Open
1 of 3 tasks
ikondov opened this issue Sep 6, 2024 · 3 comments · May be fixed by #543
Open
1 of 3 tasks

[Bug]: ModuleNotFoundError: No module named 'pytest' #535

ikondov opened this issue Sep 6, 2024 · 3 comments · May be fixed by #543
Labels

Comments

@ikondov
Copy link
Contributor

ikondov commented Sep 6, 2024

Code snippet

# On a Red Hat Enterprise Linux release 8.8 (Ootpa)
python3.9 -m venv python-3.9.16
. python-3.9.16/bin/activate
# install from main branch due to this issue: https://github.com/materialsproject/fireworks/issues/531
python -m pip install git+https://github.com/materialsproject/fireworks.git
lpad reset
lpad add_scripts date
lpad get_fws -i 1
# the last command produces error messages

What happened?

  1. I am attepting to get an overview of the firework.
  2. Expected behavior is to get only this output:
{
    "fw_id": 1,
    "created_on": "2024-09-06T08:00:38.113144",
    "updated_on": "2024-09-06T08:00:38.113207",
    "state": "READY",
    "name": "Unnamed FW"
}
  1. What happens is I get warning messages (see section Log output below) before output appears.
  2. Suggested solution: workaround: install pytest package; fix: do not print the warning messages and exception traceback.

Version

main branch

Which OS?

  • MacOS
  • Windows
  • Linux

Log output

/truncated/path/python-3.9.16/lib64/python3.9/site-packages/fireworks/utilities/fw_serializers.py:375: UserWarning: None in fireworks.user_objects.firetasks.tests.test_fileio_tasks cannot be loaded because of No module named 'pytest'. Skipping..
  warnings.warn(f"{m_object} in {mod_name} cannot be loaded because of {ex!s}. Skipping..")
Traceback (most recent call last):
  File "/truncated/path/python-3.9.16/lib64/python3.9/site-packages/fireworks/utilities/fw_serializers.py", line 368, in load_object
    m_module = importlib.import_module(mod_name)
  File "/usr/lib64/python3.9/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
  File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 850, in exec_module
  File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
  File "/truncated/path/python-3.9.16/lib64/python3.9/site-packages/fireworks/user_objects/firetasks/tests/test_fileio_tasks.py", line 10, in <module>
    import pytest
ModuleNotFoundError: No module named 'pytest'
/truncated/path/python-3.9.16/lib64/python3.9/site-packages/fireworks/utilities/fw_serializers.py:375: UserWarning: None in fireworks.user_objects.firetasks.tests.test_filepad_tasks cannot be loaded because of No module named 'pytest'. Skipping..
  warnings.warn(f"{m_object} in {mod_name} cannot be loaded because of {ex!s}. Skipping..")
Traceback (most recent call last):
  File "/truncated/path/python-3.9.16/lib64/python3.9/site-packages/fireworks/utilities/fw_serializers.py", line 368, in load_object
    m_module = importlib.import_module(mod_name)
  File "/usr/lib64/python3.9/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
  File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 850, in exec_module
  File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
  File "/truncated/path/python-3.9.16/lib64/python3.9/site-packages/fireworks/user_objects/firetasks/tests/test_filepad_tasks.py", line 6, in <module>
    import pytest
ModuleNotFoundError: No module named 'pytest'
@ikondov ikondov added the bug label Sep 6, 2024
@ikondov
Copy link
Contributor Author

ikondov commented Sep 6, 2024

This issue resembles very much issue #450. The crash here comes from another line. IMHO the code should try to catch both ImportError and ModuleNotFoundError in both lines.

@ikondov
Copy link
Contributor Author

ikondov commented Sep 6, 2024

A workaround is to install the pytest package.

@ikondov
Copy link
Contributor Author

ikondov commented Feb 3, 2025

I have edited the issue to make clear that it actually causes no crash. An annoying warning is shown telling me many times that some package, that is irrelevant for using fireworks, is not installed.

I inspected the code in more detail. Starting from this line the class ScriptTask is searched in USER_PACKAGES which include by default the directory fireworks/user_objects. The loop loads all modules from all packages in this folder by brute forces and tries to find the class ScriptTask. On the way, it encounters the modules in the test folders (obviously irrelevant and should be maybe excluded from the search, BTW: why are the tests located in the same folder as installable packages?). Nevertherless, because a test module is being loaded it raises an exception telling us that pytest is not installed. Pytest is only installed with the dev extra (see setup.py).

Also, I changed the solution, catching ModuleNotFoundError is not needed because it is subclass of ImportError. The solution is to not print the warning, but a debug log.

@ikondov ikondov linked a pull request Feb 3, 2025 that will close this issue
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant