adrienverge / yamllint

A linter for YAML files.
GNU General Public License v3.0
2.9k stars 278 forks source link

`test_run_with_user_global_config_file` fails if `XDG_CONFIG_HOME` is set #621

Closed Jayman2000 closed 10 months ago

Jayman2000 commented 11 months ago

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 commented 10 months ago

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 commented 10 months ago

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!