diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2019-05-27 21:15:47 -0400 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2019-05-27 21:17:54 -0400 |
| commit | 8b2eb2a2d0f4c7e283d96cf3e5263b5dd48e3b14 (patch) | |
| tree | 25c28c3386280d754badd49f2ef69d94617c1373 /test/ext/declarative | |
| parent | bfcf74f0bfb2ba4890f79319f31dd92758c9f8a7 (diff) | |
| download | sqlalchemy-8b2eb2a2d0f4c7e283d96cf3e5263b5dd48e3b14.tar.gz | |
Adjust test_concurrency failure modes
The test added for #4686 can raise for "B" missing which
is normal and should not fail the test. Also ensure mappers are
cleared to prevent subsequent tests elsewhere from being
affected.
Change-Id: I4c5791223e7fd21e04dcd095daa7d868e77dbd97
Diffstat (limited to 'test/ext/declarative')
| -rw-r--r-- | test/ext/declarative/test_concurrency.py | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/test/ext/declarative/test_concurrency.py b/test/ext/declarative/test_concurrency.py index b73b65ec2..42d0b13a4 100644 --- a/test/ext/declarative/test_concurrency.py +++ b/test/ext/declarative/test_concurrency.py @@ -3,18 +3,23 @@ import threading import time from sqlalchemy import Column +from sqlalchemy import exc from sqlalchemy import ForeignKey from sqlalchemy import Integer from sqlalchemy import String from sqlalchemy.ext.declarative import declarative_base from sqlalchemy.ext.declarative import declared_attr from sqlalchemy.orm import clear_mappers +from sqlalchemy.orm import exc as orm_exc from sqlalchemy.orm import relationship from sqlalchemy.orm import Session from sqlalchemy.testing import fixtures class ConcurrentUseDeclMappingTest(fixtures.TestBase): + def teardown(self): + clear_mappers() + @classmethod def make_a(cls, Base): class A(Base): @@ -34,12 +39,19 @@ class ConcurrentUseDeclMappingTest(fixtures.TestBase): A = cls.A try: s.query(A).join(A.bs) - except Exception as err: - result[0] = err - print(err) + except orm_exc.UnmappedClassError as oe: + # this is the failure mode, where B is being handled by + # declarative and is in the registry but not mapped yet. + result[0] = oe + except exc.InvalidRequestError as err: + # if make_b() starts too slowly, we can reach here, because + # B isn't in the registry yet. We can't guard against this + # case in the library because a class can refer to a name that + # doesn't exist and that has to raise. + result[0] = True else: + # no conflict result[0] = True - print("worked") @classmethod def make_b(cls, Base): @@ -74,5 +86,5 @@ class ConcurrentUseDeclMappingTest(fixtures.TestBase): for t in threads: t.join() - if isinstance(result[0], Exception): + if isinstance(result[0], orm_exc.UnmappedClassError): raise result[0] |
