-
Notifications
You must be signed in to change notification settings - Fork 2
i156: Adding the target database connection string for the insert stage logging info #175
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
base: master
Are you sure you want to change the base?
Changes from 8 commits
e6960b1
d79f0ca
c5c1513
3b8db88
7f59864
6ba171b
4393fdf
f94704b
e5f20ad
101ac57
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -631,3 +631,12 @@ def make_404(request): | |
| text=station_listing, | ||
| status_code=200, | ||
| ) | ||
|
|
||
|
|
||
| def records_contain_db_connection(test_session, caplog): | ||
| for record in caplog.records: | ||
| if "database" in record.__dict__: | ||
|
||
| logged_db = getattr(record, "database", {}) | ||
| if logged_db == test_session.bind.url.render_as_string(hide_password=True): | ||
|
||
| return True | ||
| return False | ||
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 can't tell you exactly why, but importing from
conftestis not something that is done. Fixtures are defined inconftest.py, but not utility functions.Maybe you could create this as a utility fixture as explained in this SO answer? I agree w/ the first commenter that it "feels a bit hacky", but there don't appear to be any obviously better options.
@rod-glover have you run across a requirement like this (sharing a test helper function across test modules) in your
pytesttrials?A possible explanation of why it hasn't come up to date (to my knowledge) may be that we are encouraged to keep our unit tests concise and simple. And if your test conditions are so complicated that they require more logic in an external function, then maybe they need to be simplified.
There's an argument to be made for either approach. I think I'll be happy however you choose to proceed.
Uh oh!
There was an error while loading. Please reload this page.
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 have, and I have used three methods: the hacky one, a slightly clunky one (A), and another maybe less clunky one (B).
Clunky A is to define a fixture that returns the helper function. Then use the fixture as normal. Best to scope such fixtures broadly, i.e., session scope.
Clunky B is to treat the test directory (or any subdirectory of it) as a package, with an
__init__.py. Put helper functions there, and import them using relative imports. For exampleAlternatively, create a module in such a package and import from it.
Right now B is my preferred setup.
UPDATE: Should have read the SO answer first. It is a variation of clunky A, which reads in my code more like:
I don't bother with the
Helpersclass; that seems ... unweildy and unnecessary unless you are importing a ton of helper functions ... in which case you have to ask why so many.Uh oh!
There was an error while loading. Please reload this page.
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.
In general, I like this prinicple. If you write simple functions/methods, and compose them in straightforward ways, then they are easier to understand, test and maintain. That said, some functions need somewhat complicated tests, and/or the same helper function is needed in several different places. So I treat this principle with a certain pragmatism.
Plus I do use helper functions fairly often. YMMV.
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.
Thanks, great input!