Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ Changelog
2.3.2 (unreleased)
------------------

Features:

- add ``skip`` metadata option to skip YAML tests with optional reason

- Nothing changed yet.


Expand Down
7 changes: 6 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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...

Expand All @@ -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
--------
Expand Down
6 changes: 6 additions & 0 deletions examples/test_skip.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
skip: "This test is skipped for demonstration purposes"
---
- provider: python
type: assert
expression: "1 == 1"
10 changes: 10 additions & 0 deletions pytest_play/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
34 changes: 34 additions & 0 deletions tests/test_markers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)