简体   繁体   中英

how to write integration tests using pytest and how to repeat the integration tests

I am new to this so please do not mind if the question is not specific enough.

I want to know how to club unit tests into a single integration test in pytest. Furthermore, I would like to repeat the integration test in a single test session a couple of times. Please let me know if there is a way to do this in pytest.

Scenario: I have two unit tests name test_start_call and test_end_call that are invoked by pytest in that order.

Now I wanted to repeat the process a couple of times so I did this:

for i in range(0,c): pytest.main(some command)

which works fine which will start the test session and tear down the test session as many times as I want with one call being made in each test session.

But I want to make several calls in a single test session and by far I have not found any way to do this since last two days. I tried looking into xdist but I don't want to start new processes in parallel. The integration tests should serially execute unit tests (start call and end call) as many times as I want in a single test session.

I am stuck. So any help would be great. Thank you!

review https://docs.pytest.org/en/latest/parametrize.html

Then add mult parameter to each test and implement --mult in hook pytest_generate_tests to provide the fixture value.

# conftest
def pytest_addoptions(parser):
    parser.addoption('--mult', default=1, help="run many tests")

def pytest_generate_tests(metafunc):
    mult = metafunc.config.getoption('--mult')
    if 'mult' in metafunc.fixturenames:
        for x in xrange(1, mult):
            metafunc.parametrize("mult", mult)

# testfoo
def test_start_call(mult):
    ...

From what you're saying, I'm not quite sure that you are using the right toolset. It sounds like you are either trying to load test something ( run it multiple times and see if it falls over ), or trying to do something more "data driven" - aka given input values x through y, see how it behaves.

If you are trying to do something like load testing, I'd suggest looking into something like locust .

Here is a reasonable blog with different examples on driving unit tests via different data.

Again, not sure if either of these are actually what you're looking for.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM