issues: 396215043

This data as json

id node_id number title user state locked assignee milestone comments created_at updated_at closed_at author_association pull_request body repo type active_lock_reason
396215043 MDU6SXNzdWUzOTYyMTUwNDM= 395 Find a cleaner pattern for fixtures with arguments 9599 closed 0     1 2019-01-06T00:31:22Z 2020-06-07T21:23:22Z 2020-06-07T21:23:22Z OWNER  

A lot of Datasette tests look like this:

https://github.com/simonw/datasette/blob/b65d97792a53f78cb14b226231063209d22c4602/tests/test_api.py#L438-L444

The loop here isn't actually expected to loop - it's there because the make_app_client function yields a value and then cleans it up afterwards.

This pattern works, but it is a little confusing. It would be nice to replace it with something less strange looking.

The answer may be to switch to the "factories as fixtures" pattern described here: https://docs.pytest.org/en/latest/fixture.html#factories-as-fixtures

In particular some variant of this example:

@pytest.fixture
def make_customer_record():

    created_records = []

    def _make_customer_record(name):
        record = models.Customer(name=name, orders=[])
        created_records.append(record)
        return record

    yield _make_customer_record

    for record in created_records:
        record.destroy()


def test_customer_records(make_customer_record):
    customer_1 = make_customer_record("Lisa")
    customer_2 = make_customer_record("Mike")
    customer_3 = make_customer_record("Meredith")
107914493 issue  

Links from other tables

Powered by Datasette · Query took 1.531ms · About: github-to-sqlite