mercredi 2 mai 2018

How to Parameterize Test Function: Pytest?

How do I pass a list of data, to a Test Function using Pytest? Each Test Case is pretty similar, except for this input parameter. I have tried the following but to no avail:

    import pytest

    @pytest.fixture
    def List_of_Numbers():
    list = [1,2,3,4,5,6,7,8]


    @pytest.parametrize("number", [i for item in list])
    def test_eval(number):
    assert eval(number%2) == 0


    =================================== ERRORS = 
    ===================================
    _________________________ ERROR collecting sample4.py ____ 
    _____________________
    sample4.py:8: in <module>
    @pytest.parametrize("number", [i for item in list])
    E   AttributeError: module 'pytest' has no attribute 'parametrize'
     !!!!!!!!!!!!!!!!!!! Interrupted: 1 errors during collection 
   !!!!!!!!!!!!!!!!!!!
   =========================== 1 error in 0.30 seconds 
    ===========================

Aucun commentaire:

Enregistrer un commentaire