python - "batching" of py.test fixtures for expensive operations -
i learning use test fixtures in py.test , part it's straightforward.
is there way determine test fixtures going run, ahead of time, jointly run code common dependency of group of test fixtures? have expensive operations group batch operation need know run.
example (without expensive part):
suppose have tests/test_1.py following content:
import pytest @pytest.fixture(scope='module') def tweedledee(): print "setup tweedledee" yield "tweedledee" print "teardown tweedledee" @pytest.fixture(scope='module') def tweedledum(): print "setup tweedledum" yield "tweedledum" print "teardown tweedledum" def test_tweedle(tweedledee, tweedledum): print "testing tweedle" tweedle in [tweedledee, tweedledum]: assert tweedle.startswith("tweedle") def test_dee(tweedledee): print "testing dee" assert tweedledee.endswith("dee") def test_dum(tweedledum): print "testing dum" assert tweedledum.endswith("dum") if run py.test -s see output:
tests\test_1.py setup tweedledee setup tweedledum testing tweedle .testing dee .testing dum .teardown tweedledum teardown tweedledee all -- sets tweedledee , tweedledum use 3 tests, , after tests have run, tears them down.
and if run pytest -s tests/test_1.py::test_dee run 1 test, tweedledee fixture gets setup , torn down:
tests\test_1.py setup tweedledee testing dee .teardown tweedledee here fixture content string, suppose wanted fetch 2 objects tweedledum , tweedledee remote server takes 10 seconds respond; simple way of fetching them takes 20 seconds (10 seconds per fetch), if fetch them group, take 10 seconds. (extend dozen or 2 fixtures , dilemma i'm facing.)
Comments
Post a Comment