Pytest helpers for testing projects using Meilisearch
Project description
pytest-meilisearch
pytest helpers for testing Python projects using Meilisearch.
Installation
Using a virtual environment is recommended for installing this package. Once the virtual environment is created and activated, install the package with:
pip install pytest-meilisearch
Usage
Note that to use any of the async options you also need to install an async test helper such as
pytest-asyncio. In order to use
--start-meilisearch
Docker has to be installed.
Configuration
Flags
--meilisearch-host
: Host where the Meilisearch test server is running. For examplehttp://localhost
. Default =http://127.0.0.1
(This is the same ashttp://localhost
).--meilisearch-port
: Port where the Meilisearch test server is running. For example7700
. Default =7700
.--meilisearch-master-key"
: The master key for the Meilisearch test server. Default =None
.--start-meilisearch
: Start a Meilisearch Docker container before running the tests. For this to work Docker has to be installed first. Default =False
.--meilisearch-version
: When using--start-meilisearch
the this flag will set the version of Meilisearch to start. Default =latest
.--meilisearch-start-timeout
: The number of seconds to wait for Meilisearch to start before timing out. Default = 120.
Settings
meilisearch_client_scope
: Modify the scope of the async_client and client fixtures. Valid settings arefunction
,module
,package
, orsession
. Default =function
.meilisearch_clear_indexes
: Controls is indexes are deleted after each tests. This can be useful to ensure that tests don't interfer with each other. Valid options arenone
= indexes are not deleted,async
= indexes are asyncronously deleted after each test, orsync
= indexes are syncronously deleted between each test. Default =none
.
Examples
-
Testing that your function that adds documents to an index is successful:
-
async:
async def test_my_func(async_client): docs = [ {"id": 1, "title": "Ready Player One"}, {"id": 2, "title": "The Hitchhiker's Guide to the Galaxy"}, ] index_name = "books" await my_func(index_name, docs) index = async_client.index(index_name) result = await index.get_documents() assert result.results == docs
-
sync:
def test_my_func(client): docs = [ {"id": 1, "title": "Ready Player One"}, {"id": 2, "title": "The Hitchhiker's Guide to the Galaxy"}, ] index_name = "books" my_func(index_name, docs) index = client.index(index_name) result = index.get_documents() assert result.results == docs
-
-
Testing that your search is successful:
-
async:
async def test_my_func(async_index_with_documents): docs = [ {"id": 1, "title": "Ready Player One"}, {"id": 2, "title": "The Hitchhiker's Guide to the Galaxy"}, ] index_name = "books" index = await async_index_with_documents(docs, index_name) results = await my_func("Ready Player One") expected = "Ready Player One" # Whatever you expect to be returned assert result == expected
-
sync:
def test_my_func(index_with_documents): docs = [ {"id": 1, "title": "Ready Player One"}, {"id": 2, "title": "The Hitchhiker's Guide to the Galaxy"}, ] index_name = "books" index = index_with_documents(docs, index_name) results = my_func("Ready Player One") expected = "Ready Player One" # Whatever you expect to be returned assert result == expected
-
Contributing
If you are interested in contributing to this project please see our contributing guide.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for pytest_meilisearch-0.3.5-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 25dd2b2c4ab211342b5a183cdf895065e39521dbb18cc7c7b1afb645f058d446 |
|
MD5 | fb84e12c7240b8d10a4710737530b6b6 |
|
BLAKE2b-256 | ceda152e3d02ed0835050ba061561be8816b228c6c9bedbc2ad0d34afd43ba7d |