Fix flaky filesize tests (#91200)

* Fix flaky filesize tests

* Adjust constant usage

* Once more

* Use joinpath
This commit is contained in:
epenet
2023-04-11 08:57:34 +02:00
committed by GitHub
parent 504cedaa87
commit a7093d3687
5 changed files with 49 additions and 60 deletions

View File

@@ -2,7 +2,7 @@
from __future__ import annotations
from collections.abc import Generator
import os
from pathlib import Path
from unittest.mock import patch
import pytest
@@ -10,19 +10,20 @@ import pytest
from homeassistant.components.filesize.const import DOMAIN
from homeassistant.const import CONF_FILE_PATH
from . import TEST_FILE, TEST_FILE2, TEST_FILE_NAME
from . import TEST_FILE_NAME
from tests.common import MockConfigEntry
@pytest.fixture
def mock_config_entry() -> MockConfigEntry:
def mock_config_entry(tmp_path: Path) -> MockConfigEntry:
"""Return the default mocked config entry."""
test_file = str(tmp_path.joinpath(TEST_FILE_NAME))
return MockConfigEntry(
title=TEST_FILE_NAME,
domain=DOMAIN,
data={CONF_FILE_PATH: TEST_FILE},
unique_id=TEST_FILE,
data={CONF_FILE_PATH: test_file},
unique_id=test_file,
)
@@ -33,13 +34,3 @@ def mock_setup_entry() -> Generator[None, None, None]:
"homeassistant.components.filesize.async_setup_entry", return_value=True
):
yield
@pytest.fixture(autouse=True)
def remove_file() -> None:
"""Remove test file."""
yield
if os.path.isfile(TEST_FILE):
os.remove(TEST_FILE)
if os.path.isfile(TEST_FILE2):
os.remove(TEST_FILE2)