This is a Python library to run the Specmatic library. Specmatic is a contract driven development tool that allows us to turn OpenAPI contracts into executable specifications.
- The specmatic python library is geared towards integrating Specmatic capabilities in PyTest tests.
It provides three main function:
- The ability to start and stop a python flask app in a test class
- The ability to run specmatic in test mode against a local contract/spec file, or against a spec defined in a Central Contract Repository (as defined in specmatic.json).
- The ability to stub out an api dependency using the specmatic stub feature.
NOTE: If you are using an IDE like PyCharm to run tests, please edit the test configuration and set the working directory to your project root directory.
-
To run Specmatic in test mode against a flask app, add the start_flask_app and specmatic_contract_test decorator functions on your test class:
@specmatic_contract_test(host, port) @start_flask_app(app, host, port) class TestApiContract: @classmethod def teardown_class(cls): cls.flask_server.stop()- The @start_flask_app decorator adds an attribute 'flask_server' on the test class, which can be used in the teardown method to stop the flask app.
- The @start_flask_app accepts an instance of your flask app and the host/port to run it on.
- The @specmatic_contract_test accepts host/port of your flask app and the path to the specmatic.json file in your project.
- Specmatic will look for a specmatic.json file in your project root directory. If you don't wish to use specmatic.json, you can also pass the path to the actual contract/specification file to the specmatic_contract_test decorator.
- You can run this test class either from your IDE or from command line (from your project root directory) :
pytest test -v -s
Click here to learn more about Specmatic test mode.
-
If you want to stub out a service dependency, add the specmatic_stub decorator on top of the start_flask_app.
@specmatic_contract_test(host, port) @specmatic_stub(stub_host, stub_port, [expectation_json_file]) @start_flask_app(app, host, port) class TestApiContract: @classmethod def teardown_class(cls): cls.flask_server.stop() cls.stub.stop()- The specmatic_stub decorator adds an attribute 'stub' on the test class, which can be used in the teardown method to stop the stub process.
- The @specmatic_stub accepts host/port on which the dependency is expected to be running.
- It also accepts a list of expectation json file paths which can be used to return stubbed responses.
- The Specmatic stub will look for a specmatic.json file in your project root directory. If you don't wish to use specmatic.json, you can also pass the path to the actual contract/specification file to the specmatic_stub decorator.
- Run this test class either from your IDE or from command line (from your project root directory) :
pytest test -v -s
Click here to learn more about Specmatic stub mode and using expectation json files.
Metadata
Release files for specmatic-python 0.2.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| specmatic-python-0.2.2.tar.gz | 79.1 MB | Without provenance | Details for specmatic-python-0.2.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| specmatic_python-0.2.2-py3-none-any.whl | Python 3 | none | any | Details for specmatic_python-0.2.2-py3-none-any.whl |
Total release size: 158.2 MB
Release files / specmatic-python-0.2.2.tar.gz
| Download URL | specmatic-python-0.2.2.tar.gz |
|---|---|
| Size | 79.1 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a93edb168ba197795fe043455c3f43d3c32fd9e7b0d1faf40a939fcac868b929
|
|
BLAKE2b-256 checksum How to use checksums |
e72d5b4af75a5cdc8663e11a506918e631fcf208129d32989ea4eebda15081fe
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.11.3
|
Release files / specmatic_python-0.2.2-py3-none-any.whl
| Download URL | specmatic_python-0.2.2-py3-none-any.whl |
|---|---|
| Size | 79.1 MB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
06c5fc91db7805fcd8a18d2929c26ffc6c36bf5b09e6f479ccb5941191093e95
|
|
BLAKE2b-256 checksum How to use checksums |
0c9a12f7c38b062bce644e1aa6c2f5efb2ab6d5c99c70aff3dbfa45848e39162
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.11.3
|
Security for specmatic-python 0.2.2
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.