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

Fixing broken pydantic dependency since 2.0+ breaks pytest. #585

Closed
wants to merge 1 commit into from

Conversation

tesfaldet
Copy link
Contributor

What does this PR do?

When install pytest, it'll install the latest version of pydantic and unfortunately pydantic 2.0 and higher introduces breaking changes for pytest that pytest's installation doesn't account for. So, we have to restrict the version of pydantic to be 1.10 or higher, but less than 2.0.

To reproduce, simply install the package requirements (whether through environment.yaml or requirements.txt), verify that pydantic 2.0 or higher has been installed, and run pytest.

I got this error:

ERROR tests/test_datamodules.py - ImportError: cannot import name 'ModelMetaclass' from 'pydantic.main' (/private/home/mattie/miniconda3/envs/lightning-hydra-template/lib/python3.11/site-packages/pydantic/main.py)
ERROR tests/test_datamodules.py
ERROR tests/test_eval.py - ImportError: cannot import name 'ModelMetaclass' from 'pydantic.main' (/private/home/mattie/miniconda3/envs/lightning-hydra-template/lib/python3.11/site-packages/pydantic/main.py)
ERROR tests/test_eval.py
ERROR tests/test_sweeps.py - ImportError: cannot import name 'ModelMetaclass' from 'pydantic.main' (/private/home/mattie/miniconda3/envs/lightning-hydra-template/lib/python3.11/site-packages/pydantic/main.py)
ERROR tests/test_sweeps.py
ERROR tests/test_train.py - ImportError: cannot import name 'ModelMetaclass' from 'pydantic.main' (/private/home/mattie/miniconda3/envs/lightning-hydra-template/lib/python3.11/site-packages/pydantic/main.py)
ERROR tests/test_train.py
ERROR tests/helpers/package_available.py - ImportError: cannot import name 'ModelMetaclass' from 'pydantic.main' (/private/home/mattie/miniconda3/envs/lightning-hydra-template/lib/python3.11/site-packages/pydantic/main.py)
ERROR tests/helpers/run_if.py - ImportError: cannot import name 'ModelMetaclass' from 'pydantic.main' (/private/home/mattie/miniconda3/envs/lightning-hydra-template/lib/python3.11/site-packages/pydantic/main.py)
ERROR tests/helpers/run_sh_command.py - ImportError: cannot import name 'ModelMetaclass' from 'pydantic.main' (/private/home/mattie/miniconda3/envs/lightning-hydra-template/lib/python3.11/site-packages/pydantic/main.py)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Interrupted: 11 errors during collection !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
============================================================================================================= 11 errors in 4.45s ============================================================================================================

This error makes sense considering that ModelMetaclass does not exist in pydantic.main for pydantic 2.0 or higher but does exist in 1.10.0 and higher. Restricting the pydantic version to 1.10+ and less than 2.0 fixes the problem.

Before submitting

  • Did you make sure title is self-explanatory and the description concisely explains the PR?
  • Did you make sure your PR does only one thing, instead of bundling different changes together?
  • Did you list all the breaking changes introduced by this pull request?
  • Did you test your PR locally with pytest command?
  • Did you run pre-commit hooks with pre-commit run -a command?

Did you have fun?

yepyep

@ashleve
Copy link
Owner

ashleve commented Jul 29, 2023

Hi @tesfaldet, sorry for late response. I've rerun the tests on your other PRs and they execute correctly now. I'm guessing pytest already incorporated the pydantic dependency restriction at this point.

Closing for now. Feel free to reopen if you still find something not working.

@ashleve ashleve closed this Jul 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working dependencies Pull requests that update a dependency file
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants