diff --git a/CHANGES.rst b/CHANGES.rst index 43141ef..ef0a667 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -4,6 +4,10 @@ Changelog 2.3.2 (unreleased) ------------------ +Features: + +- add ``skip`` metadata option to skip YAML tests with optional reason + - Nothing changed yet. diff --git a/README.rst b/README.rst index c755b14..f26385f 100644 --- a/README.rst +++ b/README.rst @@ -823,6 +823,7 @@ defined on the ``test_XXX.yml`` with the following format:: test_data: - username: foo - username: bar + skip: "reason for skipping" --- # omitted scenario steps in this example... @@ -837,7 +838,11 @@ Option details: the example above will be executed twice (one time with "foo" username and another time with "bar") -New options will be added in the next feature (e.g., skip scenarios, xfail, xpass, etc). +* ``skip``, you can skip the entire scenario by providing a reason string. If set to ``true``, + the scenario will be skipped without a specific reason. This is useful for temporarily + disabling tests or marking them as work in progress. + +New options will be added in the next feature (e.g., xfail, xpass, etc). Examples -------- diff --git a/examples/test_skip.yml b/examples/test_skip.yml new file mode 100644 index 0000000..e94f81b --- /dev/null +++ b/examples/test_skip.yml @@ -0,0 +1,6 @@ +--- +skip: "This test is skipped for demonstration purposes" +--- +- provider: python + type: assert + expression: "1 == 1" \ No newline at end of file diff --git a/pytest_play/plugin.py b/pytest_play/plugin.py index c607a38..28a2192 100644 --- a/pytest_play/plugin.py +++ b/pytest_play/plugin.py @@ -105,6 +105,16 @@ def pfuncobj(test_data): pass if markers: for item in values: self._add_markers(item, markers) + if metadata and 'skip' in metadata: + skip_value = metadata['skip'] + if isinstance(skip_value, str): + reason = skip_value + elif skip_value is True: + reason = None + else: + reason = str(skip_value) + for item in values: + item.add_marker(pytest.mark.skip(reason=reason)) values.sort(key=lambda item: item.reportinfo()[:2]) return values diff --git a/tests/test_markers.py b/tests/test_markers.py index c88028a..bd676a5 100644 --- a/tests/test_markers.py +++ b/tests/test_markers.py @@ -61,3 +61,37 @@ def test_autoexecute_yml_markers_strict_passed(testdir): result = testdir.runpytest('-m marker1 --strict') result.assert_outcomes(passed=1) + + +def test_autoexecute_yml_skip(testdir): + yml_file = testdir.makefile(".yml", """ +--- +skip: "Test is skipped for demonstration" +--- +- provider: python + type: assert + expression: "1" + """) + assert yml_file.basename.startswith('test_') + assert yml_file.basename.endswith('.yml') + + result = testdir.runpytest() + + result.assert_outcomes(skipped=1) + + +def test_autoexecute_yml_skip_boolean(testdir): + yml_file = testdir.makefile(".yml", """ +--- +skip: true +--- +- provider: python + type: assert + expression: "1" + """) + assert yml_file.basename.startswith('test_') + assert yml_file.basename.endswith('.yml') + + result = testdir.runpytest() + + result.assert_outcomes(skipped=1)