diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2022-01-21 18:46:37 -0500 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2022-01-22 19:17:10 -0500 |
| commit | de0b4db838e26fe61953c7765f35d5b7be581646 (patch) | |
| tree | 89f9816c86dbf9eaec0406b6a9b8585e9b645a6c /test/orm/test_events.py | |
| parent | d46a4c0326bd2e697794514b920e6727d5153324 (diff) | |
| download | sqlalchemy-de0b4db838e26fe61953c7765f35d5b7be581646.tar.gz | |
dont use exception catches for warnings; modernize xdist detection
Improvements to the test suite's integration with pytest such that the
"warnings" plugin, if manually enabled, will not interfere with the test
suite, such that third parties can enable the warnings plugin or make use
of the ``-W`` parameter and SQLAlchemy's test suite will continue to pass.
Additionally, modernized the detection of the "pytest-xdist" plugin so that
plugins can be globally disabled using PYTEST_DISABLE_PLUGIN_AUTOLOAD=1
without breaking the test suite if xdist were still installed. Warning
filters that promote deprecation warnings to errors are now localized to
SQLAlchemy-specific warnings, or within SQLAlchemy-specific sources for
general Python deprecation warnings, so that non-SQLAlchemy deprecation
warnings emitted from pytest plugins should also not impact the test suite.
Fixes: #7599
Change-Id: Ibcf09af25228d39ee5a943fda82d8a9302433726
Diffstat (limited to 'test/orm/test_events.py')
| -rw-r--r-- | test/orm/test_events.py | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/test/orm/test_events.py b/test/orm/test_events.py index 37b4d0ae1..79b20e285 100644 --- a/test/orm/test_events.py +++ b/test/orm/test_events.py @@ -35,8 +35,10 @@ from sqlalchemy.orm import UserDefinedOption from sqlalchemy.sql.cache_key import NO_CACHE from sqlalchemy.testing import assert_raises from sqlalchemy.testing import assert_raises_message +from sqlalchemy.testing import assert_warns_message from sqlalchemy.testing import AssertsCompiledSQL from sqlalchemy.testing import eq_ +from sqlalchemy.testing import expect_raises from sqlalchemy.testing import expect_warnings from sqlalchemy.testing import fixtures from sqlalchemy.testing import is_not @@ -1059,7 +1061,7 @@ class MapperEventsTest(_RemoveListeners, _fixtures.FixtureTest): m1 = Mock() self.mapper_registry.map_imperatively(User, users) - assert_raises_message( + assert_warns_message( sa.exc.SAWarning, r"before_configured' and 'after_configured' ORM events only " r"invoke with the Mapper class as " @@ -1070,7 +1072,7 @@ class MapperEventsTest(_RemoveListeners, _fixtures.FixtureTest): m1, ) - assert_raises_message( + assert_warns_message( sa.exc.SAWarning, r"before_configured' and 'after_configured' ORM events only " r"invoke with the Mapper class as " @@ -2197,7 +2199,12 @@ class SessionEventsTest(_RemoveListeners, _fixtures.FixtureTest): u2 = User(name="u1", id=1) sess.add(u2) - assert_raises(sa.exc.SAWarning, sess.commit) + + with expect_raises(sa.exc.IntegrityError), expect_warnings( + "New instance" + ): + sess.commit() + sess.rollback() eq_( canary, @@ -2249,7 +2256,11 @@ class SessionEventsTest(_RemoveListeners, _fixtures.FixtureTest): u2 = User(name="u1", id=1) sess.add(u2) - assert_raises(sa.exc.SAWarning, sess.commit) + with expect_raises(sa.exc.IntegrityError), expect_warnings( + "New instance" + ): + sess.commit() + sess.rollback() eq_(assertions, [True, True]) |
