From 89db4dbd252f8373ddc7bcfeef4508b5f4a6c93c Mon Sep 17 00:00:00 2001 From: petr-tik Date: Fri, 9 Feb 2018 22:57:55 +0000 Subject: [PATCH] Parametrized tests with a decorator Runs all tests with both trie constructors now, when adding a new test, use the same decorator and it will run the test func twice --- test.py | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/test.py b/test.py index 5260889..5df6308 100755 --- a/test.py +++ b/test.py @@ -4,30 +4,38 @@ from py_trie import PyTrie -def test_find_added(): - tr = cTrie() +constructors = [cTrie, PyTrie] + + +@pytest.mark.parametrize("constructor", constructors) +def test_find_added(constructor): + tr = constructor() tr.add("bob") assert tr.find("bob") == 1 -def test_find_incomplete(): - tr = cTrie() +@pytest.mark.parametrize("constructor", constructors) +def test_find_incomplete(constructor): + tr = constructor() tr.add("boban") assert tr.find("bob") == 0 -def test_find_missing_missing_letter_before(): - tr = cTrie() +@pytest.mark.parametrize("constructor", constructors) +def test_find_missing_missing_letter_before(constructor): + tr = constructor() tr.add("bob") assert tr.find("alice") == 0 -def test_find_missing_letters_exist_after(): - tr = cTrie() +@pytest.mark.parametrize("constructor", constructors) +def test_find_missing_letters_exist_after(constructor): + tr = constructor() tr.add("bob") assert tr.find("zlice") == 0 -def test_find_missing_before_add(): - tr = cTrie() +@pytest.mark.parametrize("constructor", constructors) +def test_find_missing_before_add(constructor): + tr = constructor() assert tr.find("me") == 0