Commit 8dcf06ac authored by Sean Kim's avatar Sean Kim Committed by Facebook GitHub Bot
Browse files

Integration test fix deleting temporary directory (#2569)

Summary:
Previous Issue: --use-tmp-hub-dir expected the temp directories used to store large file to be deleted after each test case, but pytest erases directories after 3 full test sessions. This commit fixes by manually deleting a new subdirectory created in each test case. https://github.com/pytorch/audio/pull/2565#discussion_r929007101

Pull Request resolved: https://github.com/pytorch/audio/pull/2569

Reviewed By: nateanl

Differential Revision: D38117848

Pulled By: skim0514

fbshipit-source-id: 3767cb8df1238fd6218f6aaa58d5d583cea72699
parent 81780c95
import os
import shutil
import pytest import pytest
import torch import torch
import torchaudio import torchaudio
...@@ -48,13 +51,11 @@ _CLEAN_FILES = [ ...@@ -48,13 +51,11 @@ _CLEAN_FILES = [
@pytest.fixture @pytest.fixture
def sample_speech(tmp_path, lang): def sample_speech(lang):
if lang not in _FILES: if lang not in _FILES:
raise NotImplementedError(f"Unexpected lang: {lang}") raise NotImplementedError(f"Unexpected lang: {lang}")
filename = _FILES[lang] filename = _FILES[lang]
path = tmp_path.parent / filename path = torchaudio.utils.download_asset(f"test-assets/{filename}")
if not path.exists():
torchaudio.utils.download_asset(f"test-assets/{filename}", path=path)
return path return path
...@@ -85,14 +86,16 @@ def pytest_addoption(parser): ...@@ -85,14 +86,16 @@ def pytest_addoption(parser):
@pytest.fixture(autouse=True) @pytest.fixture(autouse=True)
def temp_hub_dir(tmpdir, pytestconfig): def temp_hub_dir(tmp_path, pytestconfig):
if not pytestconfig.getoption("use_tmp_hub_dir"): if not pytestconfig.getoption("use_tmp_hub_dir"):
yield yield
else: else:
org_dir = torch.hub.get_dir() org_dir = torch.hub.get_dir()
torch.hub.set_dir(tmpdir) subdir = os.path.join(tmp_path, "hub")
torch.hub.set_dir(subdir)
yield yield
torch.hub.set_dir(org_dir) torch.hub.set_dir(org_dir)
shutil.rmtree(subdir, ignore_errors=True)
@pytest.fixture() @pytest.fixture()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment