To do this in batch for an entire test module, you can use the following pytest hook: def pytest_collection_modifyitems ( items ): for item in items : item. Forking a new subprocess for each test bypasses these limitations, and therefore my advice would be to mark any anki_session tests as forked by default. With unforked test runs, factors like that can lead to unexpected behavior, or worse still, your tests crashing. This is because, while the plugin does attempt to tear down Anki sessions as cleanly as possible on exit, this process is never quite perfect, especially for add-ons that monkey-patch Anki. You might have noticed that most of the examples above use a decorator. Additionally the plugin can provide you with a convenient way to automate testing for incompatibilities with Anki and other add-ons. functional tests, end-to-end tests, and UI tests. Where anki_session comes in handy is further towards the upper levels of the test pyramid, i.e. If you can mock your Anki runtime dependencies away, then that should always be your first tool of choice. Running your test in an Anki environment is expensive and introduces an additional layer of confounding factors. collection Additional Notes When to use pytest-anki parametrize ( "anki_session", , indirect = True ) def test_my_addon ( anki_session : AnkiSession ): # profile / collection already pre-loaded! assert anki_session.
You can customize the Anki session context by passing arguments to the anki_session fixture using pytest's indirect parametrization, e.g. forked def test_my_addon ( anki_session : AnkiSession ): with anki_session. The anki_session fixture yields an AnkiSession object that gives you access to the following attributes, among others: app - Path to Anki base directoryĪdditionally, the fixture provides a number of helpful methods and context managers, e.g. forked def test_my_addon ( anki_session : AnkiSession ): # add some tests in here
In your tests add: from pytest_anki import AnkiSession # for type checking and completions.
#Anki vs anki app install#
Installing the latest packaged build $ pip install pytest-anki Pytest-anki has only been confirmed to work on Linux so far.
#Anki vs anki app free#
I am working on bringing the docs up to speed, but until then, please feel free to check out the inline documentation and also take a look at the plug-in's tests for a number of hopefully helpful examples. Important: The plugin is currently undergoing a major rewrite and expansion of its feature-set, so the documentation below is very sparse at the moment. The goal is to provide add-on authors with a one-stop-shop for their functional testing needs, while also enabling them to QA their add-ons against a battery of different Anki versions, catching incompatibilities as they arise. deck_idsĪnki_session comes with a comprehensive API that allows developers to programmatically manipulate Anki, set up and reproduce specific configurations, simulate user interactions, and much more. deck_installed ( deck_path ) as deck_id : assert deck_id in my_addon. load_addon ( "my_addon" ) with anki_session. Pytest-anki is a pytest plugin that allows developers to write tests for their Anki add-ons.Īt its core lies the anki_session fixture that provides add-on authors with the ability to create and control headless Anki sessions to test their add-ons in: from pytest_anki import AnkiSession def test_addon_registers_deck ( anki_session : AnkiSession ): my_addon = anki_session.