test, contrib, refactor: use with when opening a file

This commit is contained in:
brunoerg
2022-04-26 14:39:07 -03:00
parent 269dcad16e
commit 027aab663a
7 changed files with 54 additions and 47 deletions

View File

@ -247,7 +247,8 @@ class ConfArgsTest(BitcoinTestFramework):
conf_file = os.path.join(default_data_dir, "bitcoin.conf")
# datadir needs to be set before [chain] section
conf_file_contents = open(conf_file, encoding='utf8').read()
with open(conf_file, encoding='utf8') as f:
conf_file_contents = f.read()
with open(conf_file, 'w', encoding='utf8') as f:
f.write(f"datadir={new_data_dir}\n")
f.write(conf_file_contents)