Skip to content

Commit

Permalink
Merge pull request #9 from sverona/parametrization-support
Browse files Browse the repository at this point in the history
Parametrization support
  • Loading branch information
gwthm-in authored Feb 15, 2023
2 parents 632e126 + b43e642 commit fd98ddb
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pytest_pspec/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ def pytest_collection_modifyitems(config, items):
parent = item.parent.obj
node_parts = item.nodeid.split('::')
node_str = node.__doc__ or node_parts[-1]

if hasattr(item, "callspec"):
node_str = node_str.format(**item.callspec.params)

mode_str = node_parts[0]
klas_str = ''
node_parts_length = len(node_parts)
Expand Down
37 changes: 37 additions & 0 deletions tests/test_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from __future__ import unicode_literals

import pytest
from _pytest.config import ExitCode


class TestReport(object):
Expand Down Expand Up @@ -180,3 +181,39 @@ def test_a_feature_is_working(self):

expected = 'This is PySpec Class'
assert expected in result.stdout.str()

def test_parametrization_succeeds(self, testdir):
testdir.makepyfile("""
import pytest
@pytest.mark.parametrize("test_input, expected", [
("3 + 5", 8),
("2 + 4", 6),
("6 * 9", 42),
])
def test_math(test_input, expected):
'''Checking if {test_input} = {expected}...'''
assert eval(test_input) == expected
""")

result = testdir.runpytest('--pspec')

expected = "3 + 5 = 8"
assert expected in result.stdout.str()

def test_parametrization_keyerrors(self, testdir):
testdir.makepyfile("""
import pytest
@pytest.mark.parametrize("test_input, expected", [
("3 + 5", 8),
("2 + 4", 6),
("6 * 9", 42),
])
def test_math(test_input, expected):
'''Checking if {missing_key} = {expected}...'''
assert eval(test_input) == expected
""")

result = testdir.runpytest('--pspec')

assert result.ret == ExitCode.INTERNAL_ERROR
assert "INTERNALERROR> KeyError: 'missing_key'" in result.stdout.lines

0 comments on commit fd98ddb

Please sign in to comment.