vendredi 4 septembre 2015

With @pytest.mark.parametrize (py.test), how to detect when data set exhausted

I use @pytest.mark.parametrize to pass test data to a test function, then I use splinter (http://ift.tt/1KPiQm8) to conduct my tests. Though I would like to know when the data set passed with parametrize will exhausted to close brower when all test have been completed. That way I don't have to initialize new browser instance each time and when data set is exhausted I can close the browser, so the test are finishing cleanly.

I found this workaround :

@pytest.mark.parametrize("controller, function, table, data, end",
    [('controller', 'function', 'table1', 'data1', {'end': False}),
     ('controller', 'function', 'table2', 'data2', {'end': True})])
def test_controller_function_table_data(controller, function, table, data, end):
    # Test stuff
    # ...
    if end['end'] is True:
        browser.quit()  # Close browser

The workaround is working ok, but I am curious to know if there is a way to check for data set exhaustion out of the box with parametrize... I did some search but can't found anything, I maybe just don't have the right keyword. I feel, like it could be a nice feature if not already implemented...

Thanks

Aucun commentaire:

Enregistrer un commentaire