diff --git a/tests/commands/test_ci.py b/tests/commands/test_ci.py index 8a597413..0f7aceed 100644 --- a/tests/commands/test_ci.py +++ b/tests/commands/test_ci.py @@ -24,7 +24,7 @@ def test_ci_empty(clirunner): assert "Invalid value: Missing argument 'src'" in result.output -def test_ci_boards(clirunner, validate_cliresult, isolated_pio_core): +def test_ci_boards(clirunner, validate_cliresult): result = clirunner.invoke( cmd_ci, [ @@ -38,7 +38,7 @@ def test_ci_boards(clirunner, validate_cliresult, isolated_pio_core): validate_cliresult(result) -def test_ci_build_dir(clirunner, tmpdir_factory, validate_cliresult, isolated_pio_core): +def test_ci_build_dir(clirunner, tmpdir_factory, validate_cliresult): build_dir = str(tmpdir_factory.mktemp("ci_build_dir")) result = clirunner.invoke( cmd_ci, @@ -54,9 +54,7 @@ def test_ci_build_dir(clirunner, tmpdir_factory, validate_cliresult, isolated_pi assert not isfile(join(build_dir, "platformio.ini")) -def test_ci_keep_build_dir( - clirunner, tmpdir_factory, validate_cliresult, isolated_pio_core -): +def test_ci_keep_build_dir(clirunner, tmpdir_factory, validate_cliresult): build_dir = str(tmpdir_factory.mktemp("ci_build_dir")) result = clirunner.invoke( cmd_ci, @@ -90,7 +88,7 @@ def test_ci_keep_build_dir( assert "board: metro" in result.output -def test_ci_project_conf(clirunner, validate_cliresult, isolated_pio_core): +def test_ci_project_conf(clirunner, validate_cliresult): project_dir = join("examples", "wiring-blink") result = clirunner.invoke( cmd_ci, @@ -104,9 +102,7 @@ def test_ci_project_conf(clirunner, validate_cliresult, isolated_pio_core): assert "uno" in result.output -def test_ci_lib_and_board( - clirunner, tmpdir_factory, validate_cliresult, isolated_pio_core -): +def test_ci_lib_and_board(clirunner, tmpdir_factory, validate_cliresult): storage_dir = str(tmpdir_factory.mktemp("lib")) result = clirunner.invoke( cmd_lib, ["--storage-dir", storage_dir, "install", "1@2.3.2"] diff --git a/tests/commands/test_test.py b/tests/commands/test_test.py index 2b6dc348..16e0556c 100644 --- a/tests/commands/test_test.py +++ b/tests/commands/test_test.py @@ -13,16 +13,14 @@ # limitations under the License. import os -import sys import pytest from platformio import util from platformio.commands.test.command import cli as cmd_test -from platformio.compat import WINDOWS -def test_local_env(isolated_pio_core): +def test_local_env(): result = util.exec_command( [ "platformio", @@ -40,7 +38,7 @@ def test_local_env(isolated_pio_core): ] -def test_multiple_env_build(clirunner, validate_cliresult, isolated_pio_core, tmpdir): +def test_multiple_env_build(clirunner, validate_cliresult, tmpdir): project_dir = tmpdir.mkdir("project") project_dir.join("platformio.ini").write( @@ -85,9 +83,7 @@ void loop() {} assert "Multiple ways to build" not in result.output -def test_setup_teardown_are_compilable( - clirunner, validate_cliresult, isolated_pio_core, tmpdir -): +def test_setup_teardown_are_compilable(clirunner, validate_cliresult, tmpdir): project_dir = tmpdir.mkdir("project") project_dir.join("platformio.ini").write( diff --git a/tests/conftest.py b/tests/conftest.py index 438ced13..56a59cbd 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -36,16 +36,9 @@ def validate_cliresult(): return decorator -@pytest.fixture(scope="module") -def clirunner(): - return CliRunner() - - -@pytest.fixture(scope="module") -def isolated_pio_core(request, tmpdir_factory): - core_dir = tmpdir_factory.mktemp(".platformio") +@pytest.fixture(scope="session") +def clirunner(request): backup_env_vars = { - "PLATFORMIO_CORE_DIR": {"new": str(core_dir)}, "PLATFORMIO_WORKSPACE_DIR": {"new": None}, } for key, item in backup_env_vars.items(): @@ -62,6 +55,19 @@ def isolated_pio_core(request, tmpdir_factory): elif key in os.environ: del os.environ[key] + request.addfinalizer(fin) + + return CliRunner() + + +@pytest.fixture(scope="module") +def isolated_pio_core(request, tmpdir_factory): + core_dir = tmpdir_factory.mktemp(".platformio") + os.environ["PLATFORMIO_CORE_DIR"] = str(core_dir) + + def fin(): + del os.environ["PLATFORMIO_CORE_DIR"] + request.addfinalizer(fin) return core_dir diff --git a/tests/test_builder.py b/tests/test_builder.py index dd0fe1f2..f220e50c 100644 --- a/tests/test_builder.py +++ b/tests/test_builder.py @@ -15,7 +15,7 @@ from platformio.commands.run.command import cli as cmd_run -def test_build_flags(clirunner, isolated_pio_core, validate_cliresult, tmpdir): +def test_build_flags(clirunner, validate_cliresult, tmpdir): build_flags = [ ("-D TEST_INT=13", "-DTEST_INT=13"), ("-DTEST_SINGLE_MACRO", "-DTEST_SINGLE_MACRO"), diff --git a/tests/test_ino2cpp.py b/tests/test_ino2cpp.py index af91da8d..d1434df7 100644 --- a/tests/test_ino2cpp.py +++ b/tests/test_ino2cpp.py @@ -31,12 +31,12 @@ def pytest_generate_tests(metafunc): metafunc.parametrize("piotest_dir", test_dirs) -def test_example(clirunner, isolated_pio_core, validate_cliresult, piotest_dir): +def test_example(clirunner, validate_cliresult, piotest_dir): result = clirunner.invoke(cmd_ci, [piotest_dir, "-b", "uno"]) validate_cliresult(result) -def test_warning_line(clirunner, isolated_pio_core, validate_cliresult): +def test_warning_line(clirunner, validate_cliresult): result = clirunner.invoke(cmd_ci, [join(INOTEST_DIR, "basic"), "-b", "uno"]) validate_cliresult(result) assert 'basic.ino:16:14: warning: #warning "Line number is 16"' in result.output