@@ -22,7 +22,6 @@ transactions using [Flask-SQLAlchemy](http://flask-sqlalchemy.pocoo.org/latest/)
2222 - [ Fixtures] ( #fixtures )
2323 - [ ` db_session ` ] ( #db_session )
2424 - [ ` db_engine ` ] ( #db_engine )
25- - [ Using the ` transactional ` mark] ( #using-the-transactional-mark )
2625- [ ** Development** ] ( #development )
2726 - [ Running the tests] ( #running-the-tests )
2827 - [ Acknowledgements] ( #acknowledgements )
@@ -117,25 +116,6 @@ def test_transaction_doesnt_persist(db_session):
117116 assert row.name != ' testing'
118117```
119118
120- Use the [ ` @pytest.mark.transactional ` mark] ( #using-the-transactional-mark )
121- to ** enforce that a test gets run inside a transaction** :
122-
123- ``` python
124- from database import db
125-
126- @pytest.mark.transactional
127- def test_db_update ():
128- row = db.session.query(Table).get(1 )
129- row.name = ' testing'
130- db.session.add(row)
131- db.session.commit()
132-
133- @pytest.mark.transactional
134- def test_db_update_doesnt_persist ():
135- row = db.session.query(Table).get(1 )
136- assert row.name != ' testing'
137- ```
138-
139119# Usage
140120
141121## Installation
@@ -262,13 +242,9 @@ rolled back when the test exits. Using these patches, you can call methods from
262242your codebase that alter database state with the knowledge that no changes will persist
263243beyond the body of the test.
264244
265- The configured patches are applied in tests where either one of two conditions
266- are true:
267-
268- 1 . a transactional fixture ([ ` db_session ` ] ( #db_session ) or [ ` db_engine ` ] ( #db_engine ) )
269- is listed as a dependency, or
270- 2 . the [ ` @pytest.mark.transactional ` ] ( #using-the-transactional-mark )
271- mark is active.
245+ The configured patches are only applied in tests where a transactional fixture
246+ (either [ ` db_session ` ] ( #db_session ) or [ ` db_engine ` ] ( #db_engine ) ) is included
247+ in the test function arguments.
272248
273249#### ` mocked-engines `
274250
@@ -386,9 +362,10 @@ The `db_session` fixture allows you to perform direct updates that will be
386362rolled back when the test exits. It exposes the same API as [ SQLAlchemy's
387363` scoped_session ` object] ( http://docs.sqlalchemy.org/en/latest/orm/contextual.html#sqlalchemy.orm.scoping.scoped_session ) .
388364
389- Listing this fixture as a dependency will activate any mocks that are specified
365+ Including this fixture as a function argument of a test will activate any mocks that are defined
390366by the configuration properties [ ` mocked-engines ` ] ( #mocked-engines ) , [ ` mocked-sessions ` ] ( #mocked-sessions ) ,
391- or [ ` mocked-sessionmakers ` ] ( #mocked-sessionmakers ) in a configuration file.
367+ or [ ` mocked-sessionmakers ` ] ( #mocked-sessionmakers ) in the test configuration file for
368+ the duration of that test.
392369
393370Example:
394371
@@ -423,10 +400,10 @@ Since `db_engine` is an instance of `MagicMock` with an `Engine` spec, other
423400methods of the ` Engine ` API can be called, but they will not perform any useful
424401work.
425402
426- Listing this fixture as a dependency will activate any mocks that are specified
427- by the configuration properties [ ` mocked-engines ` ] ( #mocked-engines ) ,
428- [ ` mocked-sessions ` ] ( #mocked-sessions ) , or [ ` mocked-sessionmakers ` ] ( #mocked-sessionmakers )
429- in a configuration file .
403+ Including this fixture as a function argument of a test will activate any mocks that are defined
404+ by the configuration properties [ ` mocked-engines ` ] ( #mocked-engines ) , [ ` mocked-sessions ` ] ( #mocked-sessions ) ,
405+ or [ ` mocked-sessionmakers ` ] ( #mocked-sessionmakers ) in the test configuration file for
406+ the duration of that test .
430407
431408Example:
432409
@@ -440,39 +417,6 @@ def test_transaction_doesnt_persist(db_engine):
440417 assert row_name != ' testing'
441418```
442419
443- ## Using the ` transactional ` mark
444-
445- If you want to enforce transactional context but you don't need to use either
446- of the built-in transactional fixtures ([ ` db_session ` ] ( #db_session ) or [ ` db_engine ` ] ( #db_engine ) ),
447- you can use the ** ` @pytest.mark.transactional ` ** decorator to mark that a test should
448- be run inside a transaction. For basic background on marks, see the [ pytest
449- documentation] ( https://docs.pytest.org/en/latest/mark.html ) .
450-
451- Note that since this approach assumes that you'll be performing database
452- updates using connections defined in your app, you ** must** mock the
453- appropriate connections using the configuration properties [ ` mocked-sessions ` ] ( #mocked-sessions ) ,
454- [ ` mocked-engines ` ] ( #mocked-engines ) , or [ ` mocked-sessionmakers ` ] ( #mocked-sessionmakers ) .
455- The ` transactional ` mark is, in essence, a way of triggering these mocks, so the mocks
456- themselves are necessary to create the transactional context that you expect.
457-
458- Example:
459-
460- ``` python
461- from database import db
462-
463- @pytest.mark.transactional
464- def test_db_update ():
465- row = db.session.query(Table).get(1 )
466- row.name = ' testing'
467- db.session.add(row)
468- db.session.commit()
469-
470- @pytest.mark.transactional
471- def test_db_update_doesnt_persist ():
472- row = db.session.query(Table).get(1 )
473- assert row.name != ' testing'
474- ```
475-
476420# Development
477421
478422## Running the tests
0 commit comments