This release is a pre-release and may not be stable for production use.
What is this?
This is a pytest plugin based on pytest-mongodb and mongomock that enables you to test your code that relies on a callback- or Future-based API for non-blocking access to a MongoDB and expects certain data to be present. It allows you to specify fixtures for database collections in JSON/BSON or YAML format. Under the hood we use the mongomock library, that you should consult for documentation on how to use MongoDB mock objects. If suitable you can also use a real MongoDB server.
Configuration
If you don’t want to put your database fixtures on the top-level directory of your package you have to specify a directory where pytest-async-mongodb looks for your data definitions.
To do so put a line like the following under the pytest section of your pytest.ini-file put a
[pytest]
async_mongodb_fixture_dir =
tests/unit/fixtures
async_mongodb_fixtures =
fixture_1
fixture_2
pytest-async-mongodb would then look for files ending in .yaml or .json in that directory.
Unlike pytest-mongodb, you cannot specify a real MongoDB connection with the pymongo client.
Basic usage
After you configured pytest-async-mongodb so that it can find your fixtures you’re ready to specify some data. Regardless of the markup language you choose, the data is provided as a list of documents (dicts). The collection that these documents are being inserted into is given by the filename of your fixture-file. E.g.: If you had a file named players.yaml with the following content:
-
name: Mario
surname: Götze
position: striker
-
name: Manuel
surname: Neuer
position: keeper
you’d end up with a collection players that has the above player definitions inserted. If your fixture file is in JSON/BSON format you can also use BSON specific types like $oid, $date, etc.
You get ahold of the database in your test-function by using the async_mongodb fixture like so:
@pytest.mark.asyncio
async def test_players(async_mongodb):
manuel = await async_mongodb.players.find_one({'name': 'Manuel'})
assert manuel['surname'] == 'Neuer'
For further information refer to the mongomock documentation.
Metadata
Release files for pytest-async-mongodb 0.0.1.dev3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pytest_async_mongodb-0.0.1.dev3-py2.py3-none-any.whl | Python 2, Python 3 | none | any | Details for pytest_async_mongodb-0.0.1.dev3-py2.py3-none-any.whl |
Release files / pytest_async_mongodb-0.0.1.dev3-py2.py3-none-any.whl
| Download URL | pytest_async_mongodb-0.0.1.dev3-py2.py3-none-any.whl |
|---|---|
| Size | 7.1 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
c925d75620d4cf190f9c9efe75ed4f9b83a1ed536bebfaab9ded2e5f9123cfdf
|
|
BLAKE2b-256 checksum How to use checksums |
b34b239e79c6813372fc58f85d0106a2f1937f2b411a68814e3ea81dc6696f15
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for pytest-async-mongodb 0.0.1.dev3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.