forked from platformio/platformio-core
Use named context meta vars for unit testing
This commit is contained in:
@ -43,7 +43,7 @@ clivars.AddVariables(
|
||||
("BUILD_SCRIPT",),
|
||||
("PROJECT_CONFIG",),
|
||||
("PIOENV",),
|
||||
("PIOTEST",),
|
||||
("PIOTEST_RUNNING_NAME",),
|
||||
("UPLOAD_PORT",)
|
||||
) # yapf: disable
|
||||
|
||||
|
@ -314,8 +314,8 @@ def ProcessTest(env):
|
||||
env.Prepend(LIBS=[unitylib])
|
||||
|
||||
src_filter = ["+<*.cpp>", "+<*.c>"]
|
||||
if "PIOTEST" in env:
|
||||
src_filter.append("+<%s%s>" % (env['PIOTEST'], sep))
|
||||
if "PIOTEST_RUNNING_NAME" in env:
|
||||
src_filter.append("+<%s%s>" % (env['PIOTEST_RUNNING_NAME'], sep))
|
||||
env.Replace(PIOTEST_SRC_FILTER=src_filter)
|
||||
|
||||
|
||||
|
@ -20,6 +20,8 @@ from platformio import exception, telemetry
|
||||
from platformio.commands.platform import \
|
||||
platform_install as cmd_platform_install
|
||||
from platformio.commands.run.helpers import _autoinstall_libdeps, print_header
|
||||
from platformio.commands.test.processor import (CTX_META_TEST_IS_RUNNING,
|
||||
CTX_META_TEST_RUNNING_NAME)
|
||||
from platformio.managers.platform import PlatformFactory
|
||||
|
||||
# pylint: disable=too-many-instance-attributes
|
||||
@ -62,7 +64,7 @@ class EnvironmentProcessor(object):
|
||||
if self.silent and not is_error:
|
||||
return True
|
||||
|
||||
if is_error or "piotest_processor" not in self.cmd_ctx.meta:
|
||||
if is_error or CTX_META_TEST_IS_RUNNING not in self.cmd_ctx.meta:
|
||||
print_header(
|
||||
"[%s] Took %.2f seconds" %
|
||||
((click.style("ERROR", fg="red", bold=True) if
|
||||
@ -74,8 +76,11 @@ class EnvironmentProcessor(object):
|
||||
|
||||
def get_build_variables(self):
|
||||
variables = {"pioenv": self.name, "project_config": self.config.path}
|
||||
if "piotest" in self.cmd_ctx.meta:
|
||||
variables['piotest'] = self.cmd_ctx.meta['piotest']
|
||||
|
||||
if CTX_META_TEST_RUNNING_NAME in self.cmd_ctx.meta:
|
||||
variables['piotest_running_name'] = self.cmd_ctx.meta[
|
||||
CTX_META_TEST_RUNNING_NAME]
|
||||
|
||||
if self.upload_port:
|
||||
# override upload port with a custom from CLI
|
||||
variables['upload_port'] = self.upload_port
|
||||
|
@ -20,7 +20,6 @@ from string import Template
|
||||
import click
|
||||
|
||||
from platformio import exception
|
||||
from platformio.commands.run import cli as cmd_run
|
||||
from platformio.commands.run.helpers import print_header
|
||||
from platformio.project.helpers import get_project_test_dir
|
||||
|
||||
@ -75,6 +74,9 @@ TRANSPORT_OPTIONS = {
|
||||
}
|
||||
}
|
||||
|
||||
CTX_META_TEST_IS_RUNNING = __name__ + ".test_running"
|
||||
CTX_META_TEST_RUNNING_NAME = __name__ + ".test_running_name"
|
||||
|
||||
|
||||
class TestProcessorBase(object):
|
||||
|
||||
@ -82,7 +84,7 @@ class TestProcessorBase(object):
|
||||
|
||||
def __init__(self, cmd_ctx, testname, envname, options):
|
||||
self.cmd_ctx = cmd_ctx
|
||||
self.cmd_ctx.meta['piotest_processor'] = True # FIXME
|
||||
self.cmd_ctx.meta[CTX_META_TEST_IS_RUNNING] = True
|
||||
self.test_name = testname
|
||||
self.options = options
|
||||
self.env_name = envname
|
||||
@ -119,12 +121,13 @@ class TestProcessorBase(object):
|
||||
self._outputcpp_generated = True
|
||||
|
||||
if self.test_name != "*":
|
||||
self.cmd_ctx.meta['piotest'] = self.test_name # FIXME
|
||||
self.cmd_ctx.meta[CTX_META_TEST_RUNNING_NAME] = self.test_name
|
||||
|
||||
if not self.options['verbose']:
|
||||
click.echo("Please wait...")
|
||||
|
||||
try:
|
||||
from platformio.commands.run import cli as cmd_run
|
||||
return self.cmd_ctx.invoke(cmd_run,
|
||||
project_dir=self.options['project_dir'],
|
||||
upload_port=self.options['upload_port'],
|
||||
|
Reference in New Issue
Block a user