From 0e3a2401aa176e5c5be05d66983e31f3b169a524 Mon Sep 17 00:00:00 2001 From: Ilya Kulakov Date: Tue, 25 Apr 2023 16:29:15 -0700 Subject: [PATCH] tests: Fix ResourceWarning due to dangling TarFile. --- test_git_archive_all.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/test_git_archive_all.py b/test_git_archive_all.py index bcaa015..05ef622 100644 --- a/test_git_archive_all.py +++ b/test_git_archive_all.py @@ -400,10 +400,10 @@ def test_ignore(contents, exclude, tmpdir, git_env, monkeypatch): repo_tar_path = os_path_join(tmpdir.strpath, 'repo.tar') repo.archive(repo_tar_path, exclude=exclude) - repo_tar = TarFile(repo_tar_path, format=PAX_FORMAT, encoding='utf-8') - expected = make_expected_tree(contents, exclude) - actual = make_actual_tree(repo_tar) + with TarFile(repo_tar_path, format=PAX_FORMAT, encoding='utf-8') as repo_tar: + expected = make_expected_tree(contents, exclude) + actual = make_actual_tree(repo_tar) assert actual == expected @@ -426,10 +426,10 @@ def test_cli(tmpdir, git_env, monkeypatch): repo_tar_path = os_path_join(tmpdir.strpath, 'repo.tar') git_archive_all.main(['git_archive_all.py', '--prefix', '', '-C', repo_path, repo_tar_path]) - repo_tar = TarFile(repo_tar_path, format=PAX_FORMAT, encoding='utf-8') - expected = make_expected_tree(contents) - actual = make_actual_tree(repo_tar) + with TarFile(repo_tar_path, format=PAX_FORMAT, encoding='utf-8') as repo_tar: + expected = make_expected_tree(contents) + actual = make_actual_tree(repo_tar) assert actual == expected