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

test_run_with_user_global_config_file fails if XDG_CONFIG_HOME is set #621

Closed
Jayman2000 opened this issue Dec 30, 2023 · 2 comments · Fixed by #623
Closed

test_run_with_user_global_config_file fails if XDG_CONFIG_HOME is set #621

Jayman2000 opened this issue Dec 30, 2023 · 2 comments · Fixed by #623

Comments

@Jayman2000
Copy link
Contributor

I’m running NixOS, and on my system, the XDG_CONFIG_HOME environment variable is set by default. This causes one of the unit tests to fail. You should be able to reproduce this issue on any system by running:

XDG_CONFIG_HOME="$PWD" python -m unittest tests.test_cli.CommandLineTestCase.test_run_with_user_global_config_file

I can workaround the problem by doing this:

env --unset=XDG_CONFIG_HOME python -m unittest tests.test_cli.CommandLineTestCase.test_run_with_user_global_config_file

Here’s what I think that the problem is: The test sets the HOME variable in an attempt to get yamllint to load an alternative global configuration file, but yamllint doesn’t look in the user’s home directory for a global configuration if XDG_CONFIG_HOME is set.

@adrienverge
Copy link
Owner

Hello Jason,

Thanks for reporting this, I can confirm the problem when XDG_CONFIG_HOME is set in environment.

Here’s what I think that the problem is: The test sets the HOME variable in an attempt to get yamllint to load an alternative global configuration file, but yamllint doesn’t look in the user’s home directory for a global configuration if XDG_CONFIG_HOME is set.

I think you are right: https://github.com/adrienverge/yamllint/blob/3288d05/yamllint/cli.py#L184-L188.

Do you think deleting / restoring XDG_CONFIG_HOME in this problematic test would be a good solution? If yes, would you like to implement it?

@Jayman2000
Copy link
Contributor Author

Do you think deleting / restoring XDG_CONFIG_HOME in this problematic test would be a good solution?

Yeah.

If yes, would you like to implement it?

Sure!

Jayman2000 added a commit to Jayman2000/yamllint-pr that referenced this issue Dec 31, 2023
Several environment variables can influence which config file yamllint
chooses to use [1]. Before this change, if you set those environment
variables and ran “python -m unittest discover”, then you could cause
certain tests to use the wrong config file and fail.

Fixes adrienverge#621.

[1]: <https://github.com/adrienverge/yamllint/blob/152ba20f339588a872777eafb888f0073e83cafb/yamllint/cli.py#L180-L188>
Jayman2000 added a commit to Jayman2000/yamllint-pr that referenced this issue Dec 31, 2023
Several environment variables can influence which config file yamllint
chooses to use [1]. Before this change, if you set those environment
variables and ran “python -m unittest discover”, then you could cause
certain tests to use the wrong config file and fail.

Fixes adrienverge#621.

[1]: <https://github.com/adrienverge/yamllint/blob/152ba20f339588a872777eafb888f0073e83cafb/yamllint/cli.py#L180-L188>
adrienverge pushed a commit that referenced this issue Jan 4, 2024
Several environment variables can influence which config file yamllint
chooses to use [1]. Before this change, if you set those environment
variables and ran “python -m unittest discover”, then you could cause
certain tests to use the wrong config file and fail.

Fixes #621.

[1]: <https://github.com/adrienverge/yamllint/blob/152ba20f339588a872777eafb888f0073e83cafb/yamllint/cli.py#L180-L188>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants