Skip to content

Commit bb81254

Browse files
committed
Added some more details on usage
1 parent 0902cba commit bb81254

1 file changed

Lines changed: 29 additions & 5 deletions

File tree

README.md

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,36 @@
22
SQLAlchemy related fixtures to handle connections and transactions with SQLAlchemy in tests.
33

44
## Fixtures
5-
This plugin provides the following fixtures:
5+
This plugin provides the following fixtures which gives access to the SQLAlchmey objects of the same name.
66

7-
1. **engine** The engine used to connect to the database. Scope is "module".
8-
1. **connection** An open connection to the database. Scope is "module".
9-
1. **transaction** A started transaction on the connection. Transaction will be rolled back. No Scope.
10-
1. **dbsession** A sqlalchemy session *not* bound to any model. No scope.
7+
* **engine** The engine used to connect to the database. Scope is "module".
8+
* **connection** An open connection to the database. Scope is "module".
9+
10+
See [Working with Engines and Conncetions](http://docs.sqlalchemy.org/en/latest/core/connections.html#module-sqlalchemy.engine) on how to use this fixtues.
11+
12+
* **transaction** A started transaction on the connection. Transaction will be rolled back. No Scope.
13+
14+
See [Using Transactions](http://docs.sqlalchemy.org/en/latest/core/connections.html#using-transactions) on how to use this fixtures
15+
16+
* **dbsession** A sqlalchemy session *not* bound to any model. No scope.
17+
18+
See [Session Basisc](http://docs.sqlalchemy.org/en/latest/orm/session_basics.html#session-basics) to learn about how to use sessions.
19+
20+
## Usage
21+
The fixtures can be used in your tests like any other [Pytest Fixtures](https://docs.pytest.org/en/3.6.1/fixture.html).
22+
23+
**Example**:
24+
25+
```python
26+
import pytest
27+
from pytest_sqlalchemy import connection
28+
29+
def test_connection(connection):
30+
# Do fancy stuff with the connection.
31+
# Note you will not need to close the connection. This is done
32+
# automatically when the scope (module) of the fixtures ends.
33+
assert connection
34+
````
1135

1236
## Invoke
1337
You need to provide the connection URL for the engine when invoking the pytest command::

0 commit comments

Comments
 (0)