Skip to content

Commit d34a0bf

Browse files
committed
Merge pull request schireson#64 from schireson/dc/ensure-history-is-refreshed
2 parents 7db8f21 + a255f81 commit d34a0bf

File tree

16 files changed

+252
-61
lines changed

16 files changed

+252
-61
lines changed

.github/workflows/build.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ jobs:
2828
sqlalchemy-version: ["1.3", "1.4"]
2929

3030
steps:
31-
- uses: actions/checkout@v2
32-
- uses: actions/setup-python@v2
31+
- uses: actions/checkout@v3
32+
- uses: actions/setup-python@v4
3333
with:
3434
python-version: ${{ matrix.python-version }}
3535
- name: Install poetry
@@ -38,7 +38,7 @@ jobs:
3838
poetry-version: "1.2"
3939

4040
- name: Set up cache
41-
uses: actions/cache@v2
41+
uses: actions/cache@v3
4242
with:
4343
path: ~/.cache/pypoetry/virtualenvs
4444
key: venv-${{ runner.os }}-${{ matrix.python-version }}-${{ matrix.pytest-version }}-${{ matrix.pytest-asyncio-version }}-${{ matrix.sqlalchemy-version }}-${{ hashFiles('**/poetry.lock') }}

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,6 @@ shell.nix
5959

6060
# Documentation
6161
docs/_*
62+
63+
# Generated by test runs.
64+
examples/test_generate_revision/test_migration.py

CHANGELOG.md

Lines changed: 79 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,136 +1,172 @@
11
# Changelog
22

3-
## [Unreleased](https://github.com/schireson/pytest-alembic/compare/v0.7.0...HEAD) (2022-02-08)
3+
## [Unreleased](https://github.com/schireson/pytest-alembic/compare/v0.8.3...HEAD) (2022-10-31)
44

55
### Fixes
66

7-
* (Huge speed optimization) Avoid the use of the high-level alembic command interface in most cases. 1ae311f
7+
* Refresh alembic history to enable tests generate new revisions to be aware of
8+
those revisions.
9+
([a81b5f8](https://github.com/schireson/pytest-alembic/commit/a81b5f82cbf0243f045cc41263a56bb788fc260d))
10+
* Compatibility with newer versions of pytest and pytest-asyncio.
11+
([4ed809b](https://github.com/schireson/pytest-alembic/commit/4ed809b8b059091cbd55aa68d57d398c129a7d3f))
12+
* Correctly insert the root package during metaadata detection.
13+
([d719608](https://github.com/schireson/pytest-alembic/commit/d71960884a6e47176d21e64e14d987bdc09715f0))
814

15+
### [v0.8.3](https://github.com/schireson/pytest-alembic/compare/v0.8.2...v0.8.3) (2022-07-20)
16+
17+
### [v0.8.2](https://github.com/schireson/pytest-alembic/compare/v0.8.1...v0.8.2) (2022-04-10)
18+
19+
#### Fixes
20+
21+
* Add missing connection param to table_at_revision.
22+
([a20d16e](https://github.com/schireson/pytest-alembic/commit/a20d16e42c9cec5f1062e2b7d3072eae42ef5534))
23+
* Improve test options for all_models_register_on_metadata.
24+
([28b7f59](https://github.com/schireson/pytest-alembic/commit/28b7f5950e5239f81c6b46a0b4265b0ed73fcb10))
25+
26+
### [v0.8.1](https://github.com/schireson/pytest-alembic/compare/v0.8.0...v0.8.1) (2022-03-12)
27+
28+
#### Fixes
29+
30+
* Add missing explicit reexports.
31+
([d5375ad](https://github.com/schireson/pytest-alembic/commit/d5375ad3cba6066826c2ac4df3220d20433d381e))
32+
33+
## [v0.8.0](https://github.com/schireson/pytest-alembic/compare/v0.7.0...v0.8.0) (2022-02-08)
34+
35+
### Fixes
36+
37+
* (Huge speed optimization) Avoid the use of the high-level alembic command
38+
interface in most cases.
39+
([d616ffa](https://github.com/schireson/pytest-alembic/commit/d616ffaacc83acdd48b6ace0b517ceb35aaf0172))
940

1041
## [v0.7.0](https://github.com/schireson/pytest-alembic/compare/v0.6.1...v0.7.0) (2021-12-21)
1142

1243
### ⚠ BREAKING CHANGE
1344

14-
* Starting with this release, python 3.6 will no longer be tested or officially supported. In this specific release, only the new official support for asyncio-based engine with alembic and pytest-alembic is incompatible with 3.6. Any existing usage should remain at least provisionally compatible until later releases which may or may not further break compatibility.
45+
* Starting with this release, python 3.6 will no longer be tested or officiallysupported. In this specific release, only the new official support forasyncio-based engine with alembic and pytest-alembic is incompatible with 3.6.Any existing usage should remain at least provisionally compatible until laterreleases which may or may not further break compatibility.
1546

1647
### Features
1748

18-
* Enable in-test insertion of data in async contexts. e9f8d97
49+
* Enable in-test insertion of data in async contexts.
50+
([e9f8d97](https://github.com/schireson/pytest-alembic/commit/e9f8d9726e1a6a9032aa773db8dc1b69cc81cc5a))
1951

2052
### Fixes
2153

22-
* asynchronous engine tests which perform transaction manipulation. 245f9ef
23-
54+
* asynchronous engine tests which perform transaction manipulation.
55+
([245f9ef](https://github.com/schireson/pytest-alembic/commit/245f9ef4e94f82d5d7742407451bcd0ad12762ac))
2456

2557
### [v0.6.1](https://github.com/schireson/pytest-alembic/compare/v0.6.0...v0.6.1) (2021-12-02)
2658

2759
#### Fixes
2860

29-
* Add missing alembic Config options. c3cab87
30-
61+
* Add missing alembic Config options.
62+
([c3cab87](https://github.com/schireson/pytest-alembic/commit/c3cab870677ebe690fb2e82170f2af3981e2ebeb))
3163

3264
## [v0.6.0](https://github.com/schireson/pytest-alembic/compare/v0.5.1...v0.6.0) (2021-11-30)
3365

3466
### Features
3567

36-
* Add ability to set a minimum bound downgrade migration cda6937
37-
* Add new test which asserts parity between upgrade and downgrade detectable effects. ab9b645
38-
* Add new test for roundtrip downgrade isolation. 2fb20d0
68+
* Add ability to set a minimum bound downgrade migration
69+
([cda6937](https://github.com/schireson/pytest-alembic/commit/cda69378272a70efc40535e13546f50b5fdc7d74))
70+
* Add new test which asserts parity between upgrade and downgrade detectable
71+
effects.
72+
([ab9b645](https://github.com/schireson/pytest-alembic/commit/ab9b6450988ff000899ff8ee193a309a3ff6c9a3))
73+
* Add new test for roundtrip downgrade isolation.
74+
([2fb20d0](https://github.com/schireson/pytest-alembic/commit/2fb20d0b8d17a70d84252832ee36fad020b06a68))
3975

4076
### Fixes
4177

42-
* Run pytest tests inline (faster and easier coverage). ea9b59d
43-
78+
* Run pytest tests inline (faster and easier coverage).
79+
([ea9b59d](https://github.com/schireson/pytest-alembic/commit/ea9b59dc61ac537fa5648273878c628094dbae71))
4480

4581
### [v0.5.1](https://github.com/schireson/pytest-alembic/compare/v0.5.0...v0.5.1) (2021-11-23)
4682

4783
#### Fixes
4884

49-
* Increase minimum python version to 3.6+ (this was already true!). e6bdfe6
50-
* Incompatibility of branched history downgrade strategy with alembic 1.6+. 192686b
51-
* ensure the up-down consistency test actually verifies migrations a2e9d13
52-
85+
* Increase minimum python version to 3.6+ (this was already true!).
86+
([e6bdfe6](https://github.com/schireson/pytest-alembic/commit/e6bdfe67f7d0bf8e675eeefa38cd44a06847799f))
87+
* Incompatibility of branched history downgrade strategy with alembic 1.6+.
88+
([192686b](https://github.com/schireson/pytest-alembic/commit/192686b9f3eaf43e8109c9376b9a806352f3a8c7))
89+
* ensure the up-down consistency test actually verifies migrations
90+
([a2e9d13](https://github.com/schireson/pytest-alembic/commit/a2e9d1321b378036e19af8e9525d78eddac09a37))
5391

5492
## [v0.5.0](https://github.com/schireson/pytest-alembic/compare/v0.4.0...v0.5.0) (2021-09-03)
5593

5694
### Features
5795

58-
* Add experimental test to identify tables which alembic will not recognize. d12e342
96+
* Add experimental test to identify tables which alembic will not recognize.
97+
([d12e342](https://github.com/schireson/pytest-alembic/commit/d12e3422f2123eb0395e3b4a4535fdf9d2676f4a))
5998

6099
### Fixes
61100

62-
* Add back missing lint job. 80242f3
63-
101+
* Add back missing lint job.
102+
([80242f3](https://github.com/schireson/pytest-alembic/commit/80242f3e4c4fc7e0120b44a4a03a4eecead2c51e))
64103

65104
## [v0.4.0](https://github.com/schireson/pytest-alembic/compare/v0.3.3...v0.4.0) (2021-08-16)
66105

67106
### Features
68107

69-
* Create a mechanism in which to create multiple alembic runner fixtures. ef1d5da
70-
* Allow alembic Config to be used directly in alembic_config fixture. 3b00103
108+
* Create a mechanism in which to create multiple alembic runner fixtures.
109+
([ef1d5da](https://github.com/schireson/pytest-alembic/commit/ef1d5daec9d66e256a4b1b8a742d6889fbbbc44d))
110+
* Allow alembic Config to be used directly in alembic_config fixture.
111+
([3b00103](https://github.com/schireson/pytest-alembic/commit/3b0010398fd245a44e6ce16f9765a2e4c0c45c66))
71112

72113
### Fixes
73114

74-
* Run covtest on all branches. f1bd6ac
75-
115+
* Run covtest on all branches.
116+
([f1bd6ac](https://github.com/schireson/pytest-alembic/commit/f1bd6aca6196cbea4674f4b6d1c1eee204cee387))
76117

77118
### [v0.3.3](https://github.com/schireson/pytest-alembic/compare/v0.3.2...v0.3.3) (2021-08-04)
78119

79120
#### Fixes
80121

81-
* Conditionally set script_location. a26f59b
82-
122+
* Conditionally set script_location.
123+
([a26f59b](https://github.com/schireson/pytest-alembic/commit/a26f59b8b737eff8e77e663f23623024377e5371))
83124

84125
### [v0.3.2](https://github.com/schireson/pytest-alembic/compare/v0.3.1...v0.3.2) (2021-08-04)
85126

86-
87127
### [v0.3.1](https://github.com/schireson/pytest-alembic/compare/v0.3.0...v0.3.1) (2021-05-10)
88128

89-
90129
## [v0.3.0](https://github.com/schireson/pytest-alembic/compare/v0.2.6...v0.3.0) (2021-05-10)
91130

92-
93131
### [v0.2.6](https://github.com/schireson/pytest-alembic/compare/v0.2.5...v0.2.6) (2021-04-26)
94132

95-
96133
### [v0.2.5](https://github.com/schireson/pytest-alembic/compare/v0.2.4...v0.2.5) (2020-07-13)
97134

98135
#### Features
99136

100-
* Allow the customization of the location at which the built in tests are executed. 255c95c
101-
137+
* Allow the customization of the location at which the built in tests are
138+
executed.
139+
([255c95c](https://github.com/schireson/pytest-alembic/commit/255c95c8edf0055f9d97aa671590449600b3e2a4))
102140

103141
### [v0.2.4](https://github.com/schireson/pytest-alembic/compare/v0.2.3...v0.2.4) (2020-07-01)
104142

105143
#### Fixes
106144

107-
* Require dataclasses only below 3.7, as it is included in stdlib 3.7 onward. 0b30fb4
108-
145+
* Require dataclasses only below 3.7, as it is included in stdlib 3.7 onward.
146+
([0b30fb4](https://github.com/schireson/pytest-alembic/commit/0b30fb41bebf702102b09c55bba18931158d94ef))
109147

110148
### [v0.2.3](https://github.com/schireson/pytest-alembic/compare/v0.2.2...v0.2.3) (2020-06-26)
111149

112150
#### Features
113151

114-
* Reduce the multiple pages of traceback output to a few lines of context that are actually meaningful to a failed test. d9bcfcc
115-
152+
* Reduce the multiple pages of traceback output to a few lines of context that are
153+
actually meaningful to a failed test.
154+
([d9bcfcc](https://github.com/schireson/pytest-alembic/commit/d9bcfcc709421734e14f3d034bfa77f74c15729e))
116155

117156
### [v0.2.2](https://github.com/schireson/pytest-alembic/compare/v0.2.1...v0.2.2) (2020-06-25)
118157

119158
#### Features
120159

121-
* Add rendered migration body to failed model-sync test. 108db31
122-
160+
* Add rendered migration body to failed model-sync test.
161+
([108db31](https://github.com/schireson/pytest-alembic/commit/108db31b874cc199418a012f314daa47d87b310a))
123162

124163
### [v0.2.1](https://github.com/schireson/pytest-alembic/compare/v0.1.1...v0.2.1) (2020-03-23)
125164

126165
#### Fixes
127166

128-
* Fix deprecation pytest warning in 3.4. f15a86b
129-
167+
* Fix deprecation pytest warning in 3.4.
168+
([f15a86b](https://github.com/schireson/pytest-alembic/commit/f15a86bd0620606203732a3f13d454b786d21a50))
130169

131170
### [v0.1.1](https://github.com/schireson/pytest-alembic/compare/v0.1.0...v0.1.1) (2020-03-09)
132171

133-
134172
## v0.1.0 (2020-03-09)
135-
136-

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
![CircleCI](https://img.shields.io/circleci/build/gh/schireson/pytest-alembic/main)
1+
![Github Actions Build](https://github.com/schireson/pytest-alembic/actions/workflows/build.yml/badge.svg)
22
[![codecov](https://codecov.io/gh/schireson/pytest-alembic/branch/master/graph/badge.svg)](https://codecov.io/gh/schireson/pytest-alembic)
33
[![Documentation Status](https://readthedocs.org/projects/pytest-alembic/badge/?version=latest)](https://pytest-alembic.readthedocs.io/en/latest/?badge=latest)
44

5+
See the full documentation [here](https://pytest-alembic.readthedocs.io/en/latest/).
6+
57
## Introduction
68

79
A pytest plugin to test alembic migrations (with default tests) and
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
[alembic]
2+
script_location = migrations
3+
4+
[loggers]
5+
keys = root,sqlalchemy,alembic
6+
7+
[handlers]
8+
keys = console
9+
10+
[formatters]
11+
keys = generic
12+
13+
[logger_root]
14+
level = WARN
15+
handlers = console
16+
qualname =
17+
18+
[logger_sqlalchemy]
19+
level = WARN
20+
handlers =
21+
qualname = sqlalchemy.engine
22+
23+
[logger_alembic]
24+
level = INFO
25+
handlers =
26+
qualname = alembic
27+
28+
[handler_console]
29+
class = StreamHandler
30+
args = (sys.stderr,)
31+
level = NOTSET
32+
formatter = generic
33+
34+
[formatter_generic]
35+
format = %(levelname)-5.5s [%(name)s] %(message)s
36+
datefmt = %H:%M:%S

examples/test_generate_revision/conftest.py

Whitespace-only changes.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
from logging.config import fileConfig
2+
3+
from alembic import context
4+
from sqlalchemy import engine_from_config, pool
5+
6+
from models import Base
7+
8+
fileConfig(context.config.config_file_name)
9+
target_metadata = Base.metadata
10+
11+
12+
connectable = context.config.attributes.get("connection", None)
13+
14+
if connectable is None:
15+
connectable = engine_from_config(
16+
context.config.get_section(context.config.config_ini_section),
17+
prefix="sqlalchemy.",
18+
poolclass=pool.NullPool,
19+
)
20+
21+
with connectable.connect() as connection:
22+
context.configure(connection=connection, target_metadata=target_metadata)
23+
24+
with context.begin_transaction():
25+
context.run_migrations()
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
"""${message}
2+
3+
Revision ID: ${up_revision}
4+
Revises: ${down_revision | comma,n}
5+
Create Date: ${create_date}
6+
7+
"""
8+
from alembic import op
9+
import sqlalchemy as sa
10+
${imports if imports else ""}
11+
12+
# revision identifiers, used by Alembic.
13+
revision = ${repr(up_revision)}
14+
down_revision = ${repr(down_revision)}
15+
branch_labels = ${repr(branch_labels)}
16+
depends_on = ${repr(depends_on)}
17+
18+
19+
def upgrade():
20+
${upgrades if upgrades else "pass"}
21+
22+
23+
def downgrade():
24+
${downgrades if downgrades else "pass"}

examples/test_generate_revision/migrations/versions/.gitkeep

Whitespace-only changes.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from sqlalchemy import Column, types
2+
from sqlalchemy.ext.declarative import declarative_base
3+
4+
Base = declarative_base()
5+
6+
7+
class Foo(Base):
8+
__tablename__ = "foo"
9+
10+
id = Column(types.Integer(), primary_key=True)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[tool:pytest]
2+
pytest_alembic_exclude = model_definitions_match_ddl, single_head_revision
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import pytest
2+
3+
from pytest_alembic.runner import MigrationContext
4+
5+
6+
def test_generate_revision(alembic_runner: MigrationContext, alembic_engine):
7+
with pytest.raises(Exception):
8+
alembic_engine.execute("SELECT * FROM foo").fetchall()
9+
10+
alembic_runner.generate_revision(autogenerate=True, prevent_file_generation=False)
11+
alembic_runner.migrate_up_one()
12+
13+
alembic_engine.execute("INSERT INTO foo (id) VALUES (100)")
14+
15+
result = alembic_engine.execute("SELECT * FROM foo").fetchall()
16+
assert len(result) == 1

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "pytest-alembic"
3-
version = "0.9.0"
3+
version = "0.9.1"
44
description = "A pytest plugin for verifying alembic migrations."
55
authors = [
66
"Dan Cardin <[email protected]>",

0 commit comments

Comments
 (0)