Skip to content

Instantly share code, notes, and snippets.

@poros
Created October 6, 2015 01:31
Show Gist options
  • Save poros/b3a9022d85e43e45b0d3 to your computer and use it in GitHub Desktop.
Save poros/b3a9022d85e43e45b0d3 to your computer and use it in GitHub Desktop.
Build a subclass on-the-fly in a pytest fixture
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