-
Notifications
You must be signed in to change notification settings - Fork 85
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PLAT-156: Migrate test_fetch #1129
Conversation
ethho
commented
Dec 12, 2023
- Changes in PLAT-154: Migrate test_external #1127
- Changes in PLAT-155: Migrate test_external_class #1128
- cp to tests
- First pass at migrating test_fetch
test_decimal fails because its contents, a zip object, are exhausted by a previous test. Reproduce by seeing a pass then a fail when running pytest -k 'test_offset or test_decimal' tests/test_fetch.py
The following command now passes, as do all tests in this module: pytest -k 'test_offset or test_decimal' tests/test_fetch.py
@pytest.fixture | ||
def languages(lang) -> List: | ||
og_contents = lang.contents | ||
languages = og_contents.copy() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had to copy, store, and restore the contents
of this table because the contents
would change between tests. This caused some tests such as test_fetch1_step1
to fail if other tests (that sort contents
) such as test_order_by
were run before it.
assert set(result[0]) == set(attrs) | ||
|
||
def test_fetch1_step1(self, schema_any, lang, languages): | ||
assert ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added this assertion to check if upstream tests like test_offset_by
changed the contents
and broke this test.
@@ -307,7 +307,7 @@ class DecimalPrimaryKey(dj.Lookup): | |||
definition = """ | |||
id : decimal(4,3) | |||
""" | |||
contents = zip((0.1, 0.25, 3.99)) | |||
contents = list(zip((0.1, 0.25, 3.99))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Strangely, the logic in test_fetch::test_offset
would exhaust this zip object, causing it to be empty when test_fetch::test_decimal
was run, causing the latter test to fail.
It's possible that ORDER BY
on the upstream table causes DecimalPrimaryKey
to also sort (and therefore exhaust the zip object):
def test_offset(self, schema_any, lang, languages):
"""Tests offset"""
cur = lang.fetch(limit=4, offset=1, order_by=["language", "name DESC"])
Whatever the cause, changing the contents from a zip to a list prevents these tests from interfering with each other.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
zip can only be used once. Once exhausted, it's empty. So if you are using the same code more than once to populate a lookup table, you need to convert into a list first.