@@ -27,7 +27,7 @@ transactions using [Flask-SQLAlchemy](http://flask-sqlalchemy.pocoo.org/latest/)
27
27
- [ Acknowledgements] ( #acknowledgements )
28
28
- [ Copyright] ( #copyright )
29
29
30
- ## Motivation
30
+ ## < a name = " motivation " ></ a > Motivation
31
31
32
32
Inspired by [ Django's built-in support for transactional
33
33
tests] ( https://jeancochrane.com/blog/django-test-transactions ) , this plugin
@@ -37,7 +37,7 @@ apps. The goal is to make testing stateful Flask-SQLAlchemy applications easier
37
37
providing fixtures that permit the developer to ** make arbitrary database updates
38
38
with the confidence that any changes made during a test will roll back** once the test exits.
39
39
40
- ## Quick examples
40
+ ## < a name = " quick-examples " ></ a > Quick examples
41
41
42
42
Use the [ ` db_session ` fixture] ( #db_session ) to make ** database updates that won't persist beyond
43
43
the body of the test** :
@@ -116,11 +116,11 @@ def test_transaction_doesnt_persist(db_session):
116
116
assert row.name != ' testing'
117
117
```
118
118
119
- # Usage
119
+ # < a name = " usage " ></ a > Usage
120
120
121
- ## Installation
121
+ ## < a name = " installation " ></ a > Installation
122
122
123
- ### From PyPi
123
+ ### < a name = " from-pypi " ></ a > From PyPi
124
124
125
125
Install using pip:
126
126
@@ -132,7 +132,7 @@ Once installed, pytest will detect the plugin automatically during test collecti
132
132
For basic background on using third-party plugins with pytest, see the [ pytest
133
133
documentation] ( https://docs.pytest.org/en/latest/plugins.html?highlight=plugins ) .
134
134
135
- ### Development version
135
+ ### < a name = " development-version " ></ a > Development version
136
136
137
137
Clone the repo from GitHub and switch into the new directory:
138
138
@@ -153,9 +153,9 @@ Or install the plugin dependencies manually:
153
153
pip install -r requirements/main.txt
154
154
```
155
155
156
- ## Configuration
156
+ ## < a name = " configuration " ></ a > Configuration
157
157
158
- ### Conftest setup
158
+ ### < a name = " conftest-setup " ></ a > Conftest setup
159
159
160
160
This plugin assumes that a fixture called ` _db ` has been
161
161
defined in the root conftest file for your tests. The ` _db ` fixture should
@@ -226,7 +226,7 @@ def _db(database):
226
226
return database
227
227
```
228
228
229
- ### Test configuration
229
+ ### < a name = " test-configuration " ></ a > Test configuration
230
230
231
231
This plugin allows you to configure a few different properties in a
232
232
` setup.cfg ` test configuration file in order to handle the specific database connection needs
@@ -246,7 +246,7 @@ The configured patches are only applied in tests where a transactional fixture
246
246
(either [ ` db_session ` ] ( #db_session ) or [ ` db_engine ` ] ( #db_engine ) ) is included
247
247
in the test function arguments.
248
248
249
- #### ` mocked-engines `
249
+ #### < a name = " mocked-engines " ></ a > ` mocked-engines `
250
250
251
251
The ` mocked-engines ` property directs the plugin to [ patch] ( https://docs.python.org/3/library/unittest.mock.html#unittest.mock.patch )
252
252
objects in your codebase, typically SQLAlchemy [ Engine] ( http://docs.sqlalchemy.org/en/latest/core/connections.html#sqlalchemy.engine.Engine )
@@ -281,7 +281,7 @@ To patch multiple objects at once, separate the paths with a whitespace:
281
281
mocked-engines =database.engine database.second_engine
282
282
```
283
283
284
- #### ` mocked-sessions `
284
+ #### < a name = " mocked-sessions " ></ a > ` mocked-sessions `
285
285
286
286
The ` mocked-sessions ` property directs the plugin to [ patch] ( https://docs.python.org/3/library/unittest.mock.html#unittest.mock.patch )
287
287
objects in your codebase, typically SQLAlchemy [ Session] ( http://docs.sqlalchemy.org/en/latest/core/connections.html#sqlalchemy.engine.Engine )
@@ -316,7 +316,7 @@ To patch multiple objects at once, separate the paths with a whitespace:
316
316
mocked-sessions =database.db.session database.second_db.session
317
317
```
318
318
319
- #### ` mocked-sessionmakers `
319
+ #### < a name = " mocked-sessionmakers " ></ a > ` mocked-sessionmakers `
320
320
321
321
The ` mocked-sessionmakers ` property directs the plugin to [ patch] ( https://docs.python.org/3/library/unittest.mock.html#unittest.mock.patch )
322
322
objects in your codebase, typically instances of [ SQLAlchemy's ` sessionmaker `
@@ -349,14 +349,14 @@ To patch multiple objects at once, separate the paths with a whitespace.
349
349
mocked-sessionmakers =database.WorkerSessionmaker database.SecondWorkerSessionmaker
350
350
```
351
351
352
- ## Fixtures
352
+ ## < a name = " fixtures " ></ a > Fixtures
353
353
354
354
This plugin provides two fixtures for performing database updates inside nested
355
355
transactions that get rolled back at the end of a test: [ ` db_session ` ] ( #db_session ) and
356
356
[ ` db_engine ` ] ( #db_engine ) . The fixtures provide similar functionality, but
357
357
with different APIs.
358
358
359
- ### ` db_session `
359
+ ### < a name = " db_session " ></ a > ` db_session `
360
360
361
361
The ` db_session ` fixture allows you to perform direct updates that will be
362
362
rolled back when the test exits. It exposes the same API as [ SQLAlchemy's
@@ -382,7 +382,7 @@ def test_transaction_doesnt_persist(db_session):
382
382
assert row.name != ' testing'
383
383
```
384
384
385
- ### ` db_engine `
385
+ ### < a name = " db_engine " ></ a > ` db_engine `
386
386
387
387
Like [ ` db_session ` ] ( #db_session ) , the ` db_engine ` fixture allows you to perform direct updates
388
388
against the test database that will be rolled back when the test exits. It is
@@ -417,9 +417,9 @@ def test_transaction_doesnt_persist(db_engine):
417
417
assert row_name != ' testing'
418
418
```
419
419
420
- # Development
420
+ # < a name = " development " ></ a > Development
421
421
422
- ## Running the tests
422
+ ## < a name = " running-the-tests " ></ a > Running the tests
423
423
424
424
Start by ensuring that all test requirements are installed:
425
425
@@ -447,7 +447,7 @@ Finally, run the tests using pytest:
447
447
pytest
448
448
```
449
449
450
- ## Acknowledgements
450
+ ## < a name = " acknowledgements " ></ a > Acknowledgements
451
451
452
452
This plugin was initially developed for testing
453
453
[ Dedupe.io] ( https://dedupe.io ) , a web app for record linkage and entity
@@ -459,7 +459,7 @@ whose blog post ["Delightful testing with pytest and
459
459
Flask-SQLAlchemy"] ( http://alexmic.net/flask-sqlalchemy-pytest/ ) helped
460
460
establish the basic approach on which this plugin builds.
461
461
462
- ## Copyright
462
+ ## < a name = " copyright " ></ a > Copyright
463
463
464
464
Copyright (c) 2018 Jean Cochrane and DataMade. Released under the MIT License.
465
465
0 commit comments