summaryrefslogtreecommitdiff
path: root/test/sql/test_metadata.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2022-01-21 18:46:37 -0500
committerMike Bayer <mike_mp@zzzcomputing.com>2022-01-22 19:17:10 -0500
commitde0b4db838e26fe61953c7765f35d5b7be581646 (patch)
tree89f9816c86dbf9eaec0406b6a9b8585e9b645a6c /test/sql/test_metadata.py
parentd46a4c0326bd2e697794514b920e6727d5153324 (diff)
downloadsqlalchemy-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/sql/test_metadata.py')
-rw-r--r--test/sql/test_metadata.py46
1 files changed, 25 insertions, 21 deletions
diff --git a/test/sql/test_metadata.py b/test/sql/test_metadata.py
index 8a9c868be..e02f0e2ed 100644
--- a/test/sql/test_metadata.py
+++ b/test/sql/test_metadata.py
@@ -53,6 +53,7 @@ from sqlalchemy.testing import is_
from sqlalchemy.testing import is_false
from sqlalchemy.testing import is_true
from sqlalchemy.testing import mock
+from sqlalchemy.testing.assertions import expect_warnings
class MetaDataTest(fixtures.TestBase, ComparesTables):
@@ -1822,32 +1823,35 @@ class TableTest(fixtures.TestBase, AssertsCompiledSQL):
def test_pk_col_mismatch_one(self):
m = MetaData()
- assert_raises_message(
- exc.SAWarning,
+
+ with expect_warnings(
"Table 't' specifies columns 'x' as primary_key=True, "
- "not matching locally specified columns 'q'",
- Table,
- "t",
- m,
- Column("x", Integer, primary_key=True),
- Column("q", Integer),
- PrimaryKeyConstraint("q"),
- )
+ "not matching locally specified columns 'q'"
+ ):
+ Table(
+ "t",
+ m,
+ Column("x", Integer, primary_key=True),
+ Column("q", Integer),
+ PrimaryKeyConstraint("q"),
+ )
def test_pk_col_mismatch_two(self):
m = MetaData()
- assert_raises_message(
- exc.SAWarning,
+
+ with expect_warnings(
"Table 't' specifies columns 'a', 'b', 'c' as primary_key=True, "
- "not matching locally specified columns 'b', 'c'",
- Table,
- "t",
- m,
- Column("a", Integer, primary_key=True),
- Column("b", Integer, primary_key=True),
- Column("c", Integer, primary_key=True),
- PrimaryKeyConstraint("b", "c"),
- )
+ "not matching locally specified columns 'b', 'c'"
+ ):
+
+ Table(
+ "t",
+ m,
+ Column("a", Integer, primary_key=True),
+ Column("b", Integer, primary_key=True),
+ Column("c", Integer, primary_key=True),
+ PrimaryKeyConstraint("b", "c"),
+ )
@testing.emits_warning("Table 't'")
def test_pk_col_mismatch_three(self):