Created
October 6, 2015 01:31
-
-
Save poros/b3a9022d85e43e45b0d3 to your computer and use it in GitHub Desktop.
Build a subclass on-the-fly in a pytest fixture
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
def BaseRobot(object): | |
def __init__(self): | |
assert self.owner | |
@pytest.fixture | |
def robot(): | |
return type('TestRobot', (BaseRobot,), dict(owner='antonio'))() | |
# instead of | |
def TestRobot(BaseRobot): | |
owner = 'antonio' | |
@pytest.fixture | |
def robot(): | |
return TestRobot() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment