{"id":15530787,"url":"https://github.com/idlesign/pytest-stub","last_synced_at":"2025-04-23T13:05:07.592Z","repository":{"id":62584198,"uuid":"163304376","full_name":"idlesign/pytest-stub","owner":"idlesign","description":"Stub packages, modules and attributes.","archived":false,"fork":false,"pushed_at":"2020-04-28T10:31:20.000Z","size":22,"stargazers_count":9,"open_issues_count":0,"forks_count":1,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-10-03T11:24:02.749Z","etag":null,"topics":["pytest","pytest-plugin","python","python3","stub","stubbing","testing"],"latest_commit_sha":null,"homepage":"https://github.com/idlesign/pytest-stub","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/idlesign.png","metadata":{"files":{"readme":"README.rst","changelog":"CHANGELOG","contributing":"CONTRIBUTING","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-12-27T14:37:42.000Z","updated_at":"2024-06-02T00:52:57.000Z","dependencies_parsed_at":"2022-11-03T22:17:56.939Z","dependency_job_id":null,"html_url":"https://github.com/idlesign/pytest-stub","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/idlesign%2Fpytest-stub","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/idlesign%2Fpytest-stub/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/idlesign%2Fpytest-stub/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/idlesign%2Fpytest-stub/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/idlesign","download_url":"https://codeload.github.com/idlesign/pytest-stub/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":220691899,"owners_count":16688788,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["pytest","pytest-plugin","python","python3","stub","stubbing","testing"],"created_at":"2024-10-02T11:24:03.349Z","updated_at":"2024-10-20T06:05:14.688Z","avatar_url":"https://github.com/idlesign.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"pytest-stub\n===========\nhttps://github.com/idlesign/pytest-stub\n\n|release| |lic| |ci| |coverage|\n\n.. |release| image:: https://img.shields.io/pypi/v/pytest-stub.svg\n    :target: https://pypi.python.org/pypi/pytest-stub\n\n.. |lic| image:: https://img.shields.io/pypi/l/pytest-stub.svg\n    :target: https://pypi.python.org/pypi/pytest-stub\n\n.. |ci| image:: https://img.shields.io/travis/idlesign/pytest-stub/master.svg\n    :target: https://travis-ci.org/idlesign/pytest-stub\n\n.. |coverage| image:: https://img.shields.io/coveralls/idlesign/pytest-stub/master.svg\n    :target: https://coveralls.io/r/idlesign/pytest-stub\n\n\nDescription\n-----------\n\n*Stub packages, modules and attributes.*\n\nThis pytest plugin allows you to replace dependencies with stubs.\n\nIt can be useful if you want to test some code using a dependency without actually having this dependency,\nfor example if you're testing your library, which uses some parts of another library.\n\n\nRequirements\n------------\n\n* Python 3.6+\n* pytest \u003e= 2.9.0\n\n\nHow to use\n----------\n\nYou can stub dependencies either with your own custom objects or you may instruct ``pytest-stub``\nto generate functions or classes for you. Use ``stub`` fixture in your test functions, like this:\n\n.. code-block:: python\n\n    def test_django_related(stub):\n\n        stub.apply({\n            # Replace `call_command` with a generated function.\n            'django.core.management.call_command': '[func]',\n\n            # Replace `BaseCommand` with a generated class.\n            'django.core.management.base.BaseCommand': '[cls]',\n\n            # Replace `dummy` with generated MagicMock.\n            'django.dummy': '[mock]',\n\n            # Replace entire `cv2` module.\n            'cv2': '[mock]',\n\n            # Sometimes we need just a persistent (always the same) magic mock.\n            'numpy': '[mock_persist]',\n\n            # Stub multiple attributes in the same module with custom objects.\n            'django.conf': {\n                'settings': object(),\n                'some': True,\n            },\n\n        })\n\nIf we want to replace some dependency with a stub not in a fixture but globally, we can use ``stub_global()`` function\nin root ``conftest.py`` (this code will apply patch before tests, so tests will be safe to import code using dependencies).\n\n.. code-block:: python\n\n    from pytest_stub.toolbox import stub_global\n\n    stub_global({\n        'cv2': '[mock_persist]',\n    })\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fidlesign%2Fpytest-stub","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fidlesign%2Fpytest-stub","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fidlesign%2Fpytest-stub/lists"}