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

Environment variable-related test fixes #623

Merged
merged 3 commits into from
Jan 4, 2024

Conversation

Jayman2000
Copy link
Contributor

@Jayman2000 Jayman2000 commented Dec 31, 2023

See the individual commits for details.

While I was working on implementing what was discussed here, I realized that there were other edge cases where environment variables could cause problems. For example, running YAMLLINT_CONFIG_FILE=/random/binary/file python -m pytest discover caused a bunch of new test failures. I decided to implement a more robust solution that fixes the problem for more than just test_run_with_user_global_config_file.

Fixes #605. Fixes #621.

Some unittests set environment variables, but then delete them as part
of their cleanup process. Deleting them is OK. Any test that needs an
environment variable should set that environment variable itself. Once
the test process stops, any changes made to the environment will be lost
[1].

Before this change, there was one location where an environment variable
was restored to its original value instead of deleted. Restoring that
variable was unnecessary.

This commit was created to prepare for a future commit which will delete
HOME before any of the tests even start. Without this change, that
future change would crash. You can’t restore a variable that’s been
deleted.

Fixes adrienverge#605.

[1]: <https://stackoverflow.com/q/716011/7593853>
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>
Before this change one of yamllint’s tests wasn’t being run on GitHub
Actions Runners because the HOME environment variable couldn’t be
overridden. I just tested it, and it looks like the HOME variable can be
overridden now, so that test no longer needs to be skipped.
@coveralls
Copy link

coveralls commented Dec 31, 2023

Coverage Status

coverage: 99.822% (+0.4%) from 99.415%
when pulling 9679651 on Jayman2000:fix-env-interference
into 152ba20 on adrienverge:master.

Copy link
Owner

@adrienverge adrienverge left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perfect. Thank you Jason!

@adrienverge adrienverge merged commit 3513ec1 into adrienverge:master Jan 4, 2024
7 checks passed
@Jayman2000 Jayman2000 deleted the fix-env-interference branch February 5, 2024 17:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants