Use context manager instead of plain open (#1211)

Context manager with open closes the files after usage.

When the object is already a pathlib.Path i used read_text
write_text functions

In some cases pathlib.Path.open were used in context manager,
it is basically the same as builtin open.

Thanks, Konstantin Baikov!
This commit is contained in:
Konstantin Baikov 2021-03-11 17:15:49 +01:00 committed by GitHub
commit 8e18c79431
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
17 changed files with 93 additions and 63 deletions

View file

@ -49,7 +49,8 @@ def test_inspect_cli_writes_to_file(app_client):
cli, ["inspect", "fixtures.db", "--inspect-file", "foo.json"]
)
assert 0 == result.exit_code, result.output
data = json.load(open("foo.json"))
with open("foo.json") as fp:
data = json.load(fp)
assert ["fixtures"] == list(data.keys())