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

Could not find 'hydra/env/default' using compose with pytest<7 and python=3.10 #2107

Open
Jasha10 opened this issue Mar 23, 2022 · 3 comments
Labels
bug Something isn't working compose_api

Comments

@Jasha10
Copy link
Collaborator

Jasha10 commented Mar 23, 2022

This issue documents failure of Hydra's compose method when used in a pytest unit test with the following specific version pins:

  • python==3.10
  • pytest<7

This combination of python+pytest version leads to a confusing error message:

E       hydra.errors.MissingConfigException: In 'hydra/config': Could not find 'hydra/env/default'
E
E       Config search path:
E               provider=hydra, path=pkg://hydra.conf
E               provider=main, path=file:///home/rig1/dev/pysc_repro
E               provider=schema, path=structured://

../../miniconda3/lib/python3.10/site-packages/hydra/_internal/defaults_list.py:801: MissingConfigException

Steps to reproduce the error:

# a_test.py
import hydra
from hydra import compose

def test_foo() -> None:
    with hydra.initialize("."):
        compose("main")
# main.yaml
# empty
$ python --version
Python 3.10.2
$ pip install 'hydra-core==1.2.0.dev2' 'pytest<7'
...
$ pytest a_test.py
...
E       hydra.errors.MissingConfigException: In 'hydra/config': Could not find 'hydra/env/default'
...

Workarounds:

  • use python version <=3.9, or
  • use pytest version >=7, or
  • avoid using hydra.compose inside a pytest test function.

Possibly related to #1854.

System information

  • Hydra Version : 1.1.1, 1.2.0.dev2
  • Python version : 3.10
  • Virtual environment type and version : miniconda
@Jasha10 Jasha10 added the bug Something isn't working label Mar 23, 2022
@Jasha10 Jasha10 changed the title compose fails with pins pytest<7 and python=3.10 compose fails with pytest<7 and python=3.10 Mar 23, 2022
@Jasha10 Jasha10 changed the title compose fails with pytest<7 and python=3.10 Could not find 'hydra/env/default' using compose with pytest<7 and python=3.10 Mar 23, 2022
@tupiznak
Copy link

@Jasha10 hello! Got the same bug on the latest versions of packages (pytest==7.1.2, python==3.10.4, hydra-core==1.2.0).

In details:

There is a file

...
config = compose(config_name="config")
...

I use config variable in various places in the code(from config import config), because there is a microservice architecture and services cannot be started using the main function. It worked well until I uploaded it to CI (bitbucket).

On docker on local machine (with same environment like in CI) works well, but in CI got error:

E   hydra.errors.MissingConfigException: In 'hydra/config': Could not find 'hydra/env/default'
E
E   Config search path:
E   	provider=hydra, path=pkg://hydra.conf
E   	provider=main, path=file:///.../conf
E   	provider=schema, path=structured://

Solution:

After many hours of trying i figured out that hydra can't find its own default configs. So after copying this folder into my conf folder everything worked.

Perhaps, when creating a job, the hydra misses some environment variables, which stops finding its directory ... I don’t know...

@Jasha10
Copy link
Collaborator Author

Jasha10 commented Nov 25, 2022

Hi @tupiznak,

I'm not able to reproduce this error with pytest==7.1.2. I can only reproduce it with pytest<7.

$ cat a_test.py
# a_test.py
import hydra
from hydra import compose

def test_foo() -> None:
    with hydra.initialize(".", version_base=None):
        compose("config")
$ cat config.yaml # empty
$ python --version
Python 3.10.4
$ python -c 'import hydra; print(f"{hydra.__version__=}")'
hydra.__version__='1.2.0'
$ pytest --version
pytest 7.1.2
$ pytest -q a_test.py
.                                                                                                                                     [100%]
1 passed in 0.06s

@BotScutters
Copy link

BotScutters commented May 31, 2023

I'm also seeing this error while using pytest==6.2.5 in a ROS2 package with Python 3.10.6.
Has anybody else run into this or come up with any solutions besides copying the Hydra configs into the repo?

Solution:

As OP mentioned #1854 is terribly relevant. I updated pytest to 7.1.2 and all is well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working compose_api
Projects
None yet
Development

No branches or pull requests

3 participants