mirror of
https://github.com/espressif/esp-idf.git
synced 2025-08-02 04:04:31 +02:00
test: remove succeeded temp projects
also rename `tmp_path` to `work_dirpath` since it's defined in pytest
This commit is contained in:
@@ -1,8 +1,11 @@
|
|||||||
# SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD
|
# SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD
|
||||||
# SPDX-License-Identifier: Apache-2.0
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
|
import logging
|
||||||
import os
|
import os
|
||||||
|
import shutil
|
||||||
import sys
|
import sys
|
||||||
import tempfile
|
import tempfile
|
||||||
|
import typing as t
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
@@ -53,7 +56,15 @@ void app_main(void) {}
|
|||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def tmp_path() -> Path:
|
def work_dirpath() -> t.Generator[Path, None, None]:
|
||||||
os.makedirs(os.path.join(IDF_PATH, 'pytest_embedded_log'), exist_ok=True)
|
os.makedirs(os.path.join(IDF_PATH, 'pytest_embedded_log'), exist_ok=True)
|
||||||
|
|
||||||
return Path(tempfile.mkdtemp(prefix=os.path.join(IDF_PATH, 'pytest_embedded_log') + os.sep))
|
p = Path(tempfile.mkdtemp(prefix=os.path.join(IDF_PATH, 'pytest_embedded_log') + os.sep))
|
||||||
|
|
||||||
|
try:
|
||||||
|
yield p
|
||||||
|
except Exception:
|
||||||
|
logging.critical('Test is failing, Please check the log in %s', p)
|
||||||
|
raise
|
||||||
|
else:
|
||||||
|
shutil.rmtree(p)
|
||||||
|
@@ -8,19 +8,19 @@ from idf_pytest.script import SUPPORTED_TARGETS
|
|||||||
from conftest import create_project
|
from conftest import create_project
|
||||||
|
|
||||||
|
|
||||||
def test_get_all_apps_non(tmp_path: Path) -> None:
|
def test_get_all_apps_non(work_dirpath: Path) -> None:
|
||||||
create_project('foo', tmp_path)
|
create_project('foo', work_dirpath)
|
||||||
create_project('bar', tmp_path)
|
create_project('bar', work_dirpath)
|
||||||
|
|
||||||
test_related_apps, non_test_related_apps = get_all_apps([str(tmp_path)])
|
test_related_apps, non_test_related_apps = get_all_apps([str(work_dirpath)])
|
||||||
|
|
||||||
assert test_related_apps == set()
|
assert test_related_apps == set()
|
||||||
assert len(non_test_related_apps) == 2 * len(SUPPORTED_TARGETS)
|
assert len(non_test_related_apps) == 2 * len(SUPPORTED_TARGETS)
|
||||||
|
|
||||||
|
|
||||||
def test_get_all_apps_single_dut_test_script(tmp_path: Path) -> None:
|
def test_get_all_apps_single_dut_test_script(work_dirpath: Path) -> None:
|
||||||
create_project('foo', tmp_path)
|
create_project('foo', work_dirpath)
|
||||||
with open(tmp_path / 'foo' / 'pytest_get_all_apps_single_dut_test_script.py', 'w') as fw:
|
with open(work_dirpath / 'foo' / 'pytest_get_all_apps_single_dut_test_script.py', 'w') as fw:
|
||||||
fw.write(
|
fw.write(
|
||||||
"""import pytest
|
"""import pytest
|
||||||
|
|
||||||
@@ -30,18 +30,18 @@ def test_foo(dut):
|
|||||||
pass
|
pass
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
create_project('bar', tmp_path)
|
create_project('bar', work_dirpath)
|
||||||
|
|
||||||
test_related_apps, non_test_related_apps = get_all_apps([str(tmp_path)], target='all')
|
test_related_apps, non_test_related_apps = get_all_apps([str(work_dirpath)], target='all')
|
||||||
|
|
||||||
assert len(test_related_apps) == 2
|
assert len(test_related_apps) == 2
|
||||||
assert len(non_test_related_apps) == 2 * len(SUPPORTED_TARGETS) - 2
|
assert len(non_test_related_apps) == 2 * len(SUPPORTED_TARGETS) - 2
|
||||||
|
|
||||||
|
|
||||||
def test_get_all_apps_multi_dut_with_markers_test_script(tmp_path: Path) -> None:
|
def test_get_all_apps_multi_dut_with_markers_test_script(work_dirpath: Path) -> None:
|
||||||
create_project('foo', tmp_path)
|
create_project('foo', work_dirpath)
|
||||||
|
|
||||||
(tmp_path / 'foo' / 'pytest_get_all_apps_multi_dut_with_markers_test_script.py').write_text(
|
(work_dirpath / 'foo' / 'pytest_get_all_apps_multi_dut_with_markers_test_script.py').write_text(
|
||||||
"""import pytest
|
"""import pytest
|
||||||
|
|
||||||
@pytest.mark.esp32
|
@pytest.mark.esp32
|
||||||
@@ -52,15 +52,15 @@ def test_foo(dut):
|
|||||||
encoding='utf-8',
|
encoding='utf-8',
|
||||||
)
|
)
|
||||||
|
|
||||||
test_related_apps, non_test_related_apps = get_all_apps([str(tmp_path)], target='all')
|
test_related_apps, non_test_related_apps = get_all_apps([str(work_dirpath)], target='all')
|
||||||
|
|
||||||
assert len(test_related_apps) == 1
|
assert len(test_related_apps) == 1
|
||||||
assert len(non_test_related_apps) == len(SUPPORTED_TARGETS) - 1
|
assert len(non_test_related_apps) == len(SUPPORTED_TARGETS) - 1
|
||||||
|
|
||||||
|
|
||||||
def test_get_all_apps_multi_dut_test_script(tmp_path: Path) -> None:
|
def test_get_all_apps_multi_dut_test_script(work_dirpath: Path) -> None:
|
||||||
create_project('foo', tmp_path)
|
create_project('foo', work_dirpath)
|
||||||
with open(tmp_path / 'foo' / 'pytest_get_all_apps_multi_dut_test_script.py', 'w') as fw:
|
with open(work_dirpath / 'foo' / 'pytest_get_all_apps_multi_dut_test_script.py', 'w') as fw:
|
||||||
fw.write(
|
fw.write(
|
||||||
"""import pytest
|
"""import pytest
|
||||||
|
|
||||||
@@ -75,17 +75,17 @@ def test_foo(dut):
|
|||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
|
|
||||||
test_related_apps, non_test_related_apps = get_all_apps([str(tmp_path)], target='all')
|
test_related_apps, non_test_related_apps = get_all_apps([str(work_dirpath)], target='all')
|
||||||
|
|
||||||
assert len(test_related_apps) == 3 # 32, s2, s3
|
assert len(test_related_apps) == 3 # 32, s2, s3
|
||||||
assert len(non_test_related_apps) == len(SUPPORTED_TARGETS) - 3
|
assert len(non_test_related_apps) == len(SUPPORTED_TARGETS) - 3
|
||||||
|
|
||||||
|
|
||||||
def test_get_all_apps_modified_pytest_script(tmp_path: Path) -> None:
|
def test_get_all_apps_modified_pytest_script(work_dirpath: Path) -> None:
|
||||||
create_project('foo', tmp_path)
|
create_project('foo', work_dirpath)
|
||||||
create_project('bar', tmp_path)
|
create_project('bar', work_dirpath)
|
||||||
|
|
||||||
(tmp_path / 'pytest_get_all_apps_modified_pytest_script.py').write_text(
|
(work_dirpath / 'pytest_get_all_apps_modified_pytest_script.py').write_text(
|
||||||
"""import pytest
|
"""import pytest
|
||||||
import os
|
import os
|
||||||
|
|
||||||
@@ -100,20 +100,20 @@ def test_multi_foo_bar(dut):
|
|||||||
encoding='utf-8',
|
encoding='utf-8',
|
||||||
)
|
)
|
||||||
|
|
||||||
test_related_apps, non_test_related_apps = get_all_apps([str(tmp_path)], target='all')
|
test_related_apps, non_test_related_apps = get_all_apps([str(work_dirpath)], target='all')
|
||||||
assert len(test_related_apps) == 2 # foo-esp32, bar-esp32
|
assert len(test_related_apps) == 2 # foo-esp32, bar-esp32
|
||||||
assert len(non_test_related_apps) == 2 * len(SUPPORTED_TARGETS) - 2
|
assert len(non_test_related_apps) == 2 * len(SUPPORTED_TARGETS) - 2
|
||||||
|
|
||||||
test_related_apps, non_test_related_apps = get_all_apps(
|
test_related_apps, non_test_related_apps = get_all_apps(
|
||||||
[str(tmp_path)], target='all', modified_files=[], modified_components=[]
|
[str(work_dirpath)], target='all', modified_files=[], modified_components=[]
|
||||||
)
|
)
|
||||||
assert len(test_related_apps) == 0
|
assert len(test_related_apps) == 0
|
||||||
assert len(non_test_related_apps) == 0
|
assert len(non_test_related_apps) == 0
|
||||||
|
|
||||||
test_related_apps, non_test_related_apps = get_all_apps(
|
test_related_apps, non_test_related_apps = get_all_apps(
|
||||||
[str(tmp_path)],
|
[str(work_dirpath)],
|
||||||
target='all',
|
target='all',
|
||||||
modified_files=[str(tmp_path / 'pytest_get_all_apps_modified_pytest_script.py')],
|
modified_files=[str(work_dirpath / 'pytest_get_all_apps_modified_pytest_script.py')],
|
||||||
modified_components=[],
|
modified_components=[],
|
||||||
)
|
)
|
||||||
assert len(test_related_apps) == 2
|
assert len(test_related_apps) == 2
|
||||||
|
@@ -32,41 +32,41 @@ def test_foo_multi_with_marker(dut):
|
|||||||
'''
|
'''
|
||||||
|
|
||||||
|
|
||||||
def test_get_pytest_cases_single_specific(tmp_path: Path) -> None:
|
def test_get_pytest_cases_single_specific(work_dirpath: Path) -> None:
|
||||||
script = tmp_path / 'pytest_get_pytest_cases_single_specific.py'
|
script = work_dirpath / 'pytest_get_pytest_cases_single_specific.py'
|
||||||
script.write_text(TEMPLATE_SCRIPT)
|
script.write_text(TEMPLATE_SCRIPT)
|
||||||
cases = get_pytest_cases([str(tmp_path)], 'esp32')
|
cases = get_pytest_cases([str(work_dirpath)], 'esp32')
|
||||||
|
|
||||||
assert len(cases) == 1
|
assert len(cases) == 1
|
||||||
assert cases[0].targets == ['esp32']
|
assert cases[0].targets == ['esp32']
|
||||||
|
|
||||||
|
|
||||||
def test_get_pytest_cases_multi_specific(tmp_path: Path) -> None:
|
def test_get_pytest_cases_multi_specific(work_dirpath: Path) -> None:
|
||||||
script = tmp_path / 'pytest_get_pytest_cases_multi_specific.py'
|
script = work_dirpath / 'pytest_get_pytest_cases_multi_specific.py'
|
||||||
script.write_text(TEMPLATE_SCRIPT)
|
script.write_text(TEMPLATE_SCRIPT)
|
||||||
cases = get_pytest_cases([str(tmp_path)], 'esp32s2,esp32s2, esp32s3')
|
cases = get_pytest_cases([str(work_dirpath)], 'esp32s2,esp32s2, esp32s3')
|
||||||
|
|
||||||
assert len(cases) == 1
|
assert len(cases) == 1
|
||||||
assert cases[0].targets == ['esp32s2', 'esp32s2', 'esp32s3']
|
assert cases[0].targets == ['esp32s2', 'esp32s2', 'esp32s3']
|
||||||
|
|
||||||
cases = get_pytest_cases([str(tmp_path)], 'esp32s3,esp32s2,esp32s2') # order matters
|
cases = get_pytest_cases([str(work_dirpath)], 'esp32s3,esp32s2,esp32s2') # order matters
|
||||||
assert len(cases) == 0
|
assert len(cases) == 0
|
||||||
|
|
||||||
|
|
||||||
def test_get_pytest_cases_multi_all(tmp_path: Path) -> None:
|
def test_get_pytest_cases_multi_all(work_dirpath: Path) -> None:
|
||||||
script = tmp_path / 'pytest_get_pytest_cases_multi_all.py'
|
script = work_dirpath / 'pytest_get_pytest_cases_multi_all.py'
|
||||||
script.write_text(TEMPLATE_SCRIPT)
|
script.write_text(TEMPLATE_SCRIPT)
|
||||||
cases = get_pytest_cases([str(tmp_path)], CollectMode.MULTI_ALL_WITH_PARAM)
|
cases = get_pytest_cases([str(work_dirpath)], CollectMode.MULTI_ALL_WITH_PARAM)
|
||||||
|
|
||||||
assert len(cases) == 2
|
assert len(cases) == 2
|
||||||
assert cases[0].targets == ['esp32', 'esp32s2']
|
assert cases[0].targets == ['esp32', 'esp32s2']
|
||||||
assert cases[1].targets == ['esp32s2', 'esp32s2', 'esp32s3']
|
assert cases[1].targets == ['esp32s2', 'esp32s2', 'esp32s3']
|
||||||
|
|
||||||
|
|
||||||
def test_get_pytest_cases_all(tmp_path: Path) -> None:
|
def test_get_pytest_cases_all(work_dirpath: Path) -> None:
|
||||||
script = tmp_path / 'pytest_get_pytest_cases_all.py'
|
script = work_dirpath / 'pytest_get_pytest_cases_all.py'
|
||||||
script.write_text(TEMPLATE_SCRIPT)
|
script.write_text(TEMPLATE_SCRIPT)
|
||||||
cases = get_pytest_cases([str(tmp_path)], CollectMode.ALL)
|
cases = get_pytest_cases([str(work_dirpath)], CollectMode.ALL)
|
||||||
|
|
||||||
assert len(cases) == 6
|
assert len(cases) == 6
|
||||||
assert cases[0].targets == ['esp32', 'esp32s2']
|
assert cases[0].targets == ['esp32', 'esp32s2']
|
||||||
|
Reference in New Issue
Block a user