Skip to content

Commit

Permalink
tests: Don’t bother restoring HOME
Browse files Browse the repository at this point in the history
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 #605.

[1]: <https://stackoverflow.com/q/716011/7593853>
  • Loading branch information
Jayman2000 authored and adrienverge committed Jan 4, 2024
1 parent 152ba20 commit f3adc58
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ def test_run_with_user_global_config_file(self):
os.makedirs(dir)
config = os.path.join(dir, 'config')

self.addCleanup(os.environ.update, HOME=os.environ['HOME'])
self.addCleanup(os.environ.__delitem__, 'HOME')
os.environ['HOME'] = home

with open(config, 'w') as f:
Expand Down

0 comments on commit f3adc58

Please sign in to comment.