Added support for pytest marks, including skipping of tests (#2353)

Signed-off-by: Garcia Ruiz <aljanru@amazon.co.uk>

Co-authored-by: Garcia Ruiz <aljanru@amazon.co.uk>
This commit is contained in:
AMZN-AlexOteiza
2021-08-10 09:08:16 +01:00
committed by GitHub
parent 9afbd07a88
commit 4b68e6c766
@@ -6,6 +6,8 @@ SPDX-License-Identifier: Apache-2.0 OR MIT
"""
import pytest
from _pytest.skipping import pytest_runtest_setup as skipping_pytest_runtest_setup
import inspect
from typing import List
from abc import ABC
@@ -333,6 +335,10 @@ class EditorTestSuite():
next(wrap, None)
return single_run
setattr(self.obj, name, make_test_func(name, test_spec))
f = make_test_func(name, test_spec)
if hasattr(test_spec, "pytestmark"):
f.pytestmark = test_spec.pytestmark
setattr(self.obj, name, f)
# Add the shared tests, for these we will create a runner class for storing the run information
# that will be later used for selecting what tests runners will be run
@@ -359,6 +365,8 @@ class EditorTestSuite():
return result
result_func = make_func(test_spec)
if hasattr(test_spec, "pytestmark"):
result_func.pytestmark = test_spec.pytestmark
setattr(self.obj, test_spec.__name__, result_func)
runners.append(runner)
@@ -450,8 +458,15 @@ class EditorTestSuite():
def filter_session_shared_tests(session_items, shared_tests):
# Retrieve the test sub-set that was collected
# this can be less than the original set if were overriden via -k argument or similars
collected_elem_names = [test.originalname for test in session_items]
selected_shared_tests = [test for test in shared_tests if test.__name__ in collected_elem_names]
def will_run(item):
try:
skipping_pytest_runtest_setup(item)
return True
except:
return False
session_items_by_name = { item.originalname:item for item in session_items }
selected_shared_tests = [test for test in shared_tests if test.__name__ in session_items_by_name.keys() and will_run(session_items_by_name[test.__name__])]
return selected_shared_tests
@staticmethod