Created
January 9, 2015 20:42
-
-
Save magixx/cdc5aac3bfd7930dc6fb to your computer and use it in GitHub Desktop.
Fixtures as Fixture Paramaters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pytest | |
@pytest.fixture(scope="class") | |
def resource_a(request): | |
r = {'name': 'A'} | |
def fin(): | |
print ("\nteardown " + r['name']) | |
request.addfinalizer(fin) | |
return r | |
@pytest.fixture(scope="class") | |
def resource_b(request): | |
r = {'name': 'B'} | |
def fin(): | |
print ("\nteardown " + r['name']) | |
request.addfinalizer(fin) | |
return r | |
@pytest.fixture(scope="class", params=[resource_a, resource_b]) | |
def resource_multi(request): | |
r = request.param(request) | |
def fin(): | |
print ("\nMulti teardown " + r['name']) | |
request.addfinalizer(fin) | |
return r | |
class TestSomeFixtures(object): | |
def test_single_fix(self, resource_multi): | |
resource = resource_multi | |
print '\nResource Test ' + resource['name'] | |
assert resource | |
------------------------------------------------------------------------------------------ | |
$ py.test -s -q --tb=no test_fixtures.py [14:32:08] | |
Resource Test A | |
. | |
Multi teardown A | |
teardown A | |
Resource Test B | |
. | |
Multi teardown B | |
teardown B |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment