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-meilisearchthe 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.
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pytest_meilisearch-0.3.3.tar.gz.
File metadata
- Download URL: pytest_meilisearch-0.3.3.tar.gz
- Upload date:
- Size: 6.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
poetry/1.7.1 CPython/3.10.12 Linux/6.2.0-1016-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1cc0ff6578ed9a7fd4c31bd63c4f0436648ec6dcc5c1755426b4486039f6558c
|
|
| MD5 |
edc086f4f8b0d7be44f6528d216d654f
|
|
| BLAKE2b-256 |
b0c55db5a4cbe83a074bdd7982aa1ebe18e44be742798ec7248ee8fc85d50678
|
File details
Details for the file pytest_meilisearch-0.3.3-py3-none-any.whl.
File metadata
- Download URL: pytest_meilisearch-0.3.3-py3-none-any.whl
- Upload date:
- Size: 7.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
poetry/1.7.1 CPython/3.10.12 Linux/6.2.0-1016-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a73f24b12bd3bd729567239fe84ad32222245b86c4bf1ff3d800182a8028738a
|
|
| MD5 |
2217aa2a92d8337f9becb895960a57f5
|
|
| BLAKE2b-256 |
bb74df99f71a5411db712450721d19bf40bb23657eee657eaf9d8e0cbd6273db
|