Skip to content

Instantly share code, notes, and snippets.

View drocco007's full-sized avatar

Daniel Rocco drocco007

  • BrightLink Technology
  • Atlanta, GA
View GitHub Profile
@drocco007
drocco007 / _question.rst
Last active January 11, 2016 12:20
Short version: what is the best way to create fixture factories?

I'm working on a user search feature and would like some feedback about the best way to structure the creation of test data using pytest. Below I have defined a test file, test_basic.py, that defines fixture functions to create users and add them to my "database" of users:

@pytest.fixture
def user_alice():
    alice = User('Alice')
    users.append(alice)
    return alice
@drocco007
drocco007 / block_test.py
Last active December 21, 2015 05:09
Kajiki basic/nested blocks
parent = u"""
<!DOCTYPE html>
<html>
<body>
<div py:block="content">Eat your veggies!</div>
</body>
</html>
"""
child = u"""
@drocco007
drocco007 / comm.py
Created August 5, 2013 12:08
Python generator rate limiter using token bucket
from time import time, sleep
_128k = 128 * 1024
_256k = 256 * 1024
_512k = 512 * 1024
_1024k = 1024 * 1024
class TokenBucket(object):
@drocco007
drocco007 / manager.py
Last active December 18, 2015 17:39
initial thoughts on creating test extension managers
class TestExtensionManagerMixin(object):
"""Mixin base class for test extension managers."""
def over(self, extensions):
"""Set the Extensions used by this manager.
:param extensions: Pre-configured Extension instances to use
instead of loading them from entry points.
:type extensions: list of :class:`~stevedore.extension.Extension`
:returns: this extension manager instance to allow chaining on
@drocco007
drocco007 / conftest.py
Last active December 16, 2015 16:49
pytest fixture for SQLAlchemy tests to wrap each test in its own transaction, which is automatically rolled back when the test completes. Drop into a test module to enable for each test in that module. Or, put it into a package's conftest.py to enable it for every test in that package.
@pytest.fixture(autouse=True)
def close_transaction(request):
session.begin(subtransactions=True)
request.addfinalizer(session.rollback)