Skip to content
This repository has been archived by the owner on Sep 12, 2023. It is now read-only.

Can pytest fixtures be distributed? #106

Closed
peterschutt opened this issue Nov 11, 2022 · 2 comments
Closed

Can pytest fixtures be distributed? #106

peterschutt opened this issue Nov 11, 2022 · 2 comments

Comments

@peterschutt
Copy link
Member

Fixtures such as the integration test client, and the caplog fixture would be of benefit downstream if there was a way to make them available.

@gazorby
Copy link
Collaborator

gazorby commented Jan 13, 2023

Maybe by writing a pytest plugin?

I think it should be a matter of adding a starlite_saqlalchemy.testing.pytest module and updating pyproject.toml:

[tool.poetry.plugins."pytest11"]
"starlite_salqalchemy" = "starlite_saqlalchemy.testing.pytest"

Then fixtures in testing.pytest should be available downstream.

@peterschutt
Copy link
Member Author

Yes, plugin most likely the way forward!

There's also a series of things that I need to monkeypatch for testing every application that would be great to be able to be lifted into the lib here somehow. But that is probably a separate issue, and I'll open that after I finish off a refresh of example-starlite-saqlalchemy that I'm working on.

peterschutt added a commit that referenced this issue Jan 16, 2023
Adds an initial pass at a pytest plugin for testing `starlite-saqlalchemy` applications.

Includes the following fixtures:
* `is_unit_test`: a boolean that distinguishes between unit and integration tests
* `_patch_http_close`: an autouse fixture that prevents any globally instantiated http clients being closed between tests
* `_patch_sqlalchemy_plugin`: autouse fixture that patches the sqlalchemy plugin `on_shutdown` method for unittests
* `_patch_worker`: autouse fixture that patches the worker `on_app_startup` and `stop` methods for unit tests
* `app`: fixture that uses a defined import path to inject an application instance. Default path is `app.main:create_app`
* `client`: fixture that injects a starlite `TestClient` instance bound to the same app given by the `app` fixture
* `cap_logger`: a structlog capturing logger for inspecting log output

Closes #106 
Closes #232
peterschutt added a commit that referenced this issue Jan 16, 2023
Adds an initial pass at a pytest plugin for testing `starlite-saqlalchemy` applications.

Includes the following fixtures:
* `is_unit_test`: a boolean that distinguishes between unit and integration tests
* `_patch_http_close`: an autouse fixture that prevents any globally instantiated http clients being closed between tests
* `_patch_sqlalchemy_plugin`: autouse fixture that patches the sqlalchemy plugin `on_shutdown` method for unittests
* `_patch_worker`: autouse fixture that patches the worker `on_app_startup` and `stop` methods for unit tests
* `app`: fixture that uses a defined import path to inject an application instance. Default path is `app.main:create_app`
* `client`: fixture that injects a starlite `TestClient` instance bound to the same app given by the `app` fixture
* `cap_logger`: a structlog capturing logger for inspecting log output

Closes #106
Closes #232
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants