MobileDynasty / pytest-env

pytest plugin used to set environment variables
MIT License
217 stars 23 forks source link

Fails if env variable is set to JSON (curly brackets, python dict) #11

Closed Elijas closed 1 year ago

Elijas commented 5 years ago

Error

Fails with the following configuration pytest.ini

[pytest]
env =
    JSON={"key": "value"}

due to plugin.py

        # Replace environment variables in value. for instance:
        # TEST_DIR={USER}/repo_test_dir.
        value = value.format(**os.environ)

Simple suggestion:

use R: flag meaning Raw value (similar to python's r"raw string") that will skip the value.format command. Yes, this way we won't be able to use other env variables in json/dict env variables, but in the current situation it's impossible to have json/dict env variables at all!

EdgyEdgemond commented 3 years ago

Is there a work around for this? edit: The standard fix for maintaining {} in format strings through format works for this.

[pytest]
env = 
    JSON={{"key": "value"}}
gaborbernat commented 1 year ago

Development moved to https://github.com/pytest-dev/pytest-env

Elijas commented 1 year ago

Development moved to https://github.com/pytest-dev/pytest-env

Thanks for letting us know! I've recreated the issue there.

Elijas commented 1 year ago

Fixed in https://github.com/pytest-dev/pytest-env