diff options
author | Stephen Warren <swarren@nvidia.com> | 2017-09-18 11:11:49 -0600 |
---|---|---|
committer | Tom Rini <trini@konsulko.com> | 2017-09-29 14:07:53 -0400 |
commit | 2d26bf6c26b2507fb597b7d265efe7d61cb2d6b2 (patch) | |
tree | 4ce93257bc7ab934258a5c393bdb74aa5169538b /test/py/conftest.py | |
parent | d5170448ae79581af973f447ba6077118999c963 (diff) | |
download | u-boot-2d26bf6c26b2507fb597b7d265efe7d61cb2d6b2.tar.gz |
test/py: add skip marker for reliance on tools
Some tests use external tools (executables) during their operation. Add
a test.py mark to indicate this. This allows those tests to be skipped if
the required tool is not present.
Signed-off-by: Stephen Warren <swarren@nvidia.com>
Diffstat (limited to 'test/py/conftest.py')
-rw-r--r-- | test/py/conftest.py | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/test/py/conftest.py b/test/py/conftest.py index e2fc7fd7ef..6e66a48c15 100644 --- a/test/py/conftest.py +++ b/test/py/conftest.py @@ -457,6 +457,34 @@ def setup_buildconfigspec(item): if not ubconfig.buildconfig.get('config_' + option.lower(), None): pytest.skip('.config feature "%s" not enabled' % option.lower()) +def tool_is_in_path(tool): + for path in os.environ["PATH"].split(os.pathsep): + fn = os.path.join(path, tool) + if os.path.isfile(fn) and os.access(fn, os.X_OK): + return True + return False + +def setup_requiredtool(item): + """Process any 'requiredtool' marker for a test. + + Such a marker lists some external tool (binary, executable, application) + that the test requires. If tests are being executed on a system that + doesn't have the required tool, the test is marked to be skipped. + + Args: + item: The pytest test item. + + Returns: + Nothing. + """ + + mark = item.get_marker('requiredtool') + if not mark: + return + for tool in mark.args: + if not tool_is_in_path(tool): + pytest.skip('tool "%s" not in $PATH' % tool) + def start_test_section(item): anchors[item.name] = log.start_section(item.name) @@ -476,6 +504,7 @@ def pytest_runtest_setup(item): start_test_section(item) setup_boardspec(item) setup_buildconfigspec(item) + setup_requiredtool(item) def pytest_runtest_protocol(item, nextitem): """pytest hook: Called to execute a test. |