Маркер PyTest для подмножества тестов Python -Unittest ddt - PullRequest
1 голос
/ 10 марта 2020

У меня есть тестовые случаи, написанные на Python-Unittest и выполняющие их с PyTest. Я хочу добавить маркер PyTest к подмножеству ddt тестовых случаев.

Но в настоящее время могу использовать маркер PyTest для всего тестового случая. Вот так -

# cat unittest_marker.py

import unittest, ddt, pytest

@ddt.ddt
class TestCase(unittest.TestCase):
    @pytest.mark.group0
    @ddt.data("a", "b", "c")
    def test_t01(self, val):
        print("t01: {}".format(val))

Соберите все тестовые наборы, отмеченные group0

# pytest unittest_marker.py -m group0 --collect-only
============================================================================ test session starts =============================================================================
platform linux -- Python 3.6.8, pytest-4.6.3, py-1.8.0, pluggy-0.12.0
rootdir: /root/tests/python/pytest-mark
collected 3 items                                                                                                                                                            
<Module unittest_marker.py>
  <UnitTestCase TestCase>
    <TestCaseFunction test_t01_1_a>
    <TestCaseFunction test_t01_2_b>
    <TestCaseFunction test_t01_3_c>

Я хочу добавить маркер для тестового набора test_t01_1_b, как в PyTest -

# cat pytest_marker.py 

import pytest

@pytest.mark.group0
@pytest.mark.parametrize(
    ("val"), [("a"), pytest.param("b", marks=pytest.mark.group1), ("c")]
)
def test_t01(val):
    print("t01: {}".format(val))

Соберите все тестовые случаи, отмеченные group0

# pytest pytest_marker.py -m group0 --collect-only
============================================================================ test session starts =============================================================================
platform linux -- Python 3.6.8, pytest-4.6.3, py-1.8.0, pluggy-0.12.0
rootdir: /root/tests/python/pytest-mark
collected 3 items                                                                                                                                                            
<Module pytest_marker.py>
  <Function test_t01[a]>
  <Function test_t01[b]>
  <Function test_t01[c]>

Соберите все тестовые случаи, отмеченные group1

# pytest pytest_marker.py -m group1 --collect-only
============================================================================ test session starts =============================================================================
platform linux -- Python 3.6.8, pytest-4.6.3, py-1.8.0, pluggy-0.12.0
rootdir: /root/tests/python/pytest-mark
collected 3 items / 2 deselected / 1 selected                                                                                                                                
<Module pytest_marker.py>
  <Function test_t01[b]>

Есть ли способ получить PyTest как вывод с использованием Python-Unittest ddt?

...