Repository navigation
How to override pytest logging behaviour #12035
Replies: 1 comment
|
Those are two different handlers/output paths. Your custom pytest's logging plugin captures the underlying If you want pytest's captured-log section to use your format, configure pytest's log formatter: [pytest]
log_level = INFO
log_format = timestamp:%(asctime)s - logger_name:%(name)s - levelname:%(levelname)s - message:%(message)sYou can also specify it on the command line with If you do not want the duplicate Captured stdout section, remove/disable the application's stdout One other important detail: So you don't redirect the already-formatted stdout text into Please mark this answer as accepted if it helped, thank you. |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
I have created a custom logging class and I am trying to write tests for it. The class has it's own formatter, for example something like
"timestamp:%(asctime)s - logger_name:%(name)s - levelname:%(levelname)s - message:%(message)s".When i run the pytests, somehow the logs generated by this custom logger are captured in
caplogwithbasicConfigformat and on thestdoutI can see the logs in the format set by custom logging class.Following are the code snippets of how I am doing it:
How can I redirect the output of my custom logger to
"Captured log call"?All reactions