Skip to content
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

Fix flaky test test_bulk_upsert #229

Merged
merged 1 commit into from
Jun 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion app/tests/src/db/test_bulk_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,14 @@ class Number:
num: int


_next_id = 0


def get_random_number_object() -> Number:
global _next_id
_next_id += 1
return Number(
id=str(random.randint(1000000, 9999999)),
id=str(_next_id),
Comment on lines +18 to +25
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(not required - just throwing an idea out) You could use Factory boy for building these. While we normally use it for DB models, it also supports creating a dict. Mostly would help with not needing to manage a global counter.
https://github.com/navapbc/simpler-grants-gov/blob/main/api/tests/src/db/models/factories.py#L1269

Not really necessary for just this, but if this was expanded significantly in use I'd recommend it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh nice! I'll defer that change for now, thanks for sharing (also, very convenient that the grants.gov project is open source)

num=random.randint(1, 10000),
)

Expand Down
Loading