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

How to have all failure on logging pytestfile #149

Closed
MouradZoghbiWork opened this issue Dec 21, 2023 · 1 comment
Closed

How to have all failure on logging pytestfile #149

MouradZoghbiWork opened this issue Dec 21, 2023 · 1 comment

Comments

@MouradZoghbiWork
Copy link

MouradZoghbiWork commented Dec 21, 2023

Hi

i have pytest logging configuration in toml file

log_cli = true
log_auto_indent = true
log_cli_format = "UTC datetime : %(asctime)s [%(levelname)8s] %(module)s:%(filename)s:.%(lineno)3d: %(message)s"
log_cli_date_format = "%Y-%m-%d %H:%M:%S"
log_file = "Log/test_execution.log"
log_cli_level = "INFO"
log_file_level = "INFO"
log_file_date_format = "%Y-%m-%d %H:%M:%S"
log_file_format = "UTC datetime : %(asctime)s [%(levelname)8s] %(module)s:%(filename)s:.%(lineno)3d: %(message)s"

when i execute :

def test_example(self, caplog):
        a = 1
        b = 2
        c = [2, 4, 6]
        check.greater(a, b)
        check.less_equal(b, a)
        check.is_in(a, c, "Is 1 in the list")
        check.is_not_in(b, c, "make sure 2 isn't in list")

i see all failed in consol but not in logging file : Log/test_execution.log.

how can i collect all failure from console and save it into file ?

@okken
Copy link
Owner

okken commented Dec 22, 2023

pytest-check doesn't write to output through the logging module.
Results are reported through standard pytest longrepr result.

And pytest, as far as I know, does not reported to the logging module.

There is a plugin, pytest-reportlog, that creates a json file for results, and includes the longrepr, which might be what you're looking for.

However, a simple way to capture the output is just to pipe the results to a file.
Example in bash: pytest test_example.py > output.txt
or: pytest test_example.py | tee output.txt

Closing this as "works as designed"

@okken okken closed this as completed Dec 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants