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
flask_migrate.upgrade() during pytest test breaks logging #330
flask_migrate.upgrade() during pytest test breaks logging #330
Comments
Alembic was designed as a stand-alone tool. It reads all the logging options from the alembic.ini file. These options override whatever logging configuration your own application or test environment set. There are several solutions
|
@miguelgrinberg - I really appreciate the quick and thorough response. In my case, running app_test.py @@ -1,3 +1,4 @@
+import concurrent.futures as cf
import logging
import os
@@ -22,7 +23,8 @@ def test_logging(app_fixture, caplog):
logging.info(msg1)
if os.getenv('DO_UPGRADE'):
- flask_migrate.upgrade()
+ with cf.ProcessPoolExecutor() as pool:
+ pool.submit(flask_migrate.upgrade)
msg2 = "After"
logging.info(msg2) I've submitted a PR for your consideration that adds a note to the docs based on your response. |
For anyone who runs into this again. @OliverEvans96's fix didn't work for me, but this did:
Credit goes to this documentation.
|
Another work around is to just re-enable the logger..
|
Hi there,
I've been really enjoying flask-migrate, but I've spent the last few hours on a very obscure bug related to logging during testing with pytest.
EDIT: I think this is probably a duplicate of #227, but I'll post it anyways because a solution should at least appear in the documentation of this repo.
Apologies in advanced if this is just due to my ignorance of python's logging system.
Description
It seems that if I run
flask_migrate.upgrade()
during a test,caplog
does not receive logs fromlogging.info
for the rest of the test, and those logs are therefore not shown if the test fails. This issue does not occur if I run the same code outside of a test.Package versions
I'm using a clean conda env, with
Python 3.7.7
on Arch Linux, only adding the following packages:This produces the following
pip list
Minimal working example
Code available at https://github.com/OliverEvans96/pytest-logging-bug
app.py
db_schema.py
app_test.py
Reproducing the issue:
MWE Output
Any help would be appreciated. I've opened the same issue on the pytest repo at pytest-dev/pytest#7103. I'll be very curious to know what's going on here.
Thanks,
Oliver
The text was updated successfully, but these errors were encountered: