pytest dynamically generate test method
<p>Hi How can i generate test method dynamically for a list or for number of files.
Say I have file1,file2 and filen with input value in json. Now I need to run the same test for multiple values like below,</p>

<pre><code>class Test_File(unittest.TestCase):
    def test_$FILE_NAME(self):
        return_val = validate_data($FILE_NAME)
        assert return_val
</code></pre>

<p>I am using the following command to run the py.test to generate html and junit report</p>

<pre><code>py.test test_rotate.py --tb=long --junit-xml=results.xml --html=results.html -vv
</code></pre>

<p>At present I am manually defining the methods as below,</p>

<pre><code>def test_lease_file(self):
    return_val = validate_data(lease_file)
    assert return_val

def test_string_file(self):
    return_val = validate_data(string_file)
    assert return_val

 def test_data_file(self):
    return_val = validate_data(data_file)
    assert return_val
</code></pre>

<p>Please let me know how I can specify py test to dynamically generate test_came method while giving reports.</p>

<p>I am expecting exactly which is mentioned in this blog "<a href="http://eli.thegreenplace.net/2014/04/02/dynamically-generating-python-test-cases" rel="noreferrer">http://eli.thegreenplace.net/2014/04/02/dynamically-generating-python-test-cases</a>"</p>

<p>But above blog uses unittest and if I use that I am not able to generate html and junit report </p>

<p>When we use fixtures as below I get error like its requiring 2 parameters,</p>

<pre><code>test_case = []
class Memory_utlization(unittest.TestCase):
@classmethod
def setup_class(cls):
    fname = "test_order.txt"
    with open(fname) as f:
        content = f.readlines()
    file_names = []
    for i in content:
        file_names.append(i.strip())
    data = tuple(file_names)
    test_case.append(data)
    logging.info(test_case) # here test_case=[('dhcp_lease.json'),('dns_rpz.json'),]

@pytest.mark.parametrize("test_file",test_case)
def test_eval(self,test_file):
    logging.info(test_case) 
</code></pre>

<p>When I execute the above I get the following error,</p>

<pre><code> &gt;               testMethod()
 E               TypeError: test_eval() takes exactly 2 arguments (1 given)
</code></pre>