{"id":50938032,"url":"https://github.com/dimagi/pytest-unmagic-django","last_synced_at":"2026-06-17T11:03:38.962Z","repository":{"id":358150003,"uuid":"1240121116","full_name":"dimagi/pytest-unmagic-django","owner":"dimagi","description":"pytest-django support for pytest-unmagic","archived":false,"fork":false,"pushed_at":"2026-05-15T23:55:34.000Z","size":24,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-05-16T01:57:32.800Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dimagi.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-05-15T19:41:02.000Z","updated_at":"2026-05-15T23:55:55.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/dimagi/pytest-unmagic-django","commit_stats":null,"previous_names":["dimagi/pytest-unmagic-django"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/dimagi/pytest-unmagic-django","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dimagi%2Fpytest-unmagic-django","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dimagi%2Fpytest-unmagic-django/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dimagi%2Fpytest-unmagic-django/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dimagi%2Fpytest-unmagic-django/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dimagi","download_url":"https://codeload.github.com/dimagi/pytest-unmagic-django/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dimagi%2Fpytest-unmagic-django/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34445186,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-17T02:00:05.408Z","response_time":127,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2026-06-17T11:03:29.784Z","updated_at":"2026-06-17T11:03:38.947Z","avatar_url":"https://github.com/dimagi.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"pytest-unmagic-django\n=====================\n\n**pytest-django support for pytest-unmagic**\n\npytest-unmagic-django bridges [pytest-unmagic](https://github.com/dimagi/pytest-unmagic)\nand [pytest-django](https://pytest-django.readthedocs.io/) so that tests\nusing unmagic fixtures for database access work correctly with\npytest-django.\n\n\nInstallation\n------------\n\n```sh\npip install pytest-unmagic-django\n```\n\nBoth `pytest-unmagic` and `pytest-django` are installed automatically as\ndependencies. Django itself must be installed separately.\n\n\nUsage\n-----\n\n### Declaring database access\n\nUse `@use('db')` (or another pytest-django DB fixture) on a test or on a\nfixture in its chain to declare that the test needs database access:\n\n```python\nfrom unmagic import use\n\n@use('db')\ndef test_creates_record():\n    MyModel.objects.create(name='example')\n    assert MyModel.objects.count() == 1\n```\n\nThe declaration is required. Without it, the guard in\npytest-unmagic-django raises a `RuntimeError` if a DB fixture is set up\nwithout being declared, rather than silently allowing access.\n\n\n### Fixtures that need database access\n\nApply `@use('db')` to a fixture that accesses the database. Any test\nthat uses the fixture will have DB access set up automatically — the\ntest itself does not need its own `@use('db')`:\n\n```python\nfrom unmagic import fixture, use\n\n@use('db')\n@fixture\ndef seeded_person():\n    person = Person.objects.create(name='Ada')\n    yield person\n\n@use(seeded_person)\ndef test_person_name():\n    assert seeded_person().name == 'Ada'\n```\n\n\n### Chaining fixtures\n\nWhen multiple fixtures form a dependency chain, declare `@use ('db')`\nonly on the fixture that directly accesses the database.\npytest-unmagic-django walks the full `@use` chain at collection time,\nso the declaration propagates up to the test automatically:\n\n```python\nfrom unmagic import fixture, use\n\n@use('db')\n@fixture\ndef author():\n    yield Person.objects.create(name='Daedalus')\n\n@use(author)\n@fixture\ndef article():\n    yield Article.objects.create(title='On flight', author=author())\n\n@use(article)\ndef test_article_author():\n    assert article().author.name == 'Daedalus'\n```\n\n\n### Transactional tests\n\nAll pytest-django DB fixtures are supported. Use `'transactional_db'`\nfor tests that need real transactions:\n\n```python\nfrom unmagic import use\n\n@use('transactional_db')\ndef test_with_real_transactions():\n    ...\n```\n\n\nRunning the tests\n-----------------\n\n```sh\ncd path/to/pytest-unmagic-django\npip install -e \".[test]\"\npytest\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdimagi%2Fpytest-unmagic-django","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdimagi%2Fpytest-unmagic-django","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdimagi%2Fpytest-unmagic-django/lists"}