Configure Logging when running tests (scenarios)

Is it possible to run-test giving a logconf file?
I am doing this to check some logs when I run some test scenarios.
I edited the code in run-test.py to load the logger config that I wanted while keeping the basicConfig for ERROR and it works but it doesn’t seem right.
Is there a better way to do this?

There is assertLogs which can be used to test logging calls.

1 Like

Thanks for the answer. I didn’t know about asserLogs and I may use it in the future.
I think that my post may not have been clear enough. I would like to se the logs for the tests run. For this reason I want to send them to a file. For now I modified the run-test.hy. I was just wondering if there war already a way to do this, similar to -logconf.

You can use the -v flag of run-tests script to increase the verbosity of the test. Not sure if this suites your needs.

1 Like

-v flag is only for verbosity of the test. It’s interesting but I think it only print a more verbose test result. It does not print INFO/DEBUG logging messages.

We disabled logging on tests. Here is the reational: Disable logging when running tests (#9545) · Issues · Tryton / Tryton · GitLab

That’s great, not printing expected error messages on test. I just wanted to be able to see the logs of the test somewhere else (in a file).

This what I do for now just in case somebody finds this posts and wants to do a similar thing.
I added the line after basicConfig in run-test.hy to get the logs to a file for reviewing after running test:

logging.basicConfig(level=logging.ERROR)
logging.config.fileConfig('trytond-test-log.conf', disable_existing_loggers=False)

I find it useful when I am writing scenarios to find and fix issues by adding log messages and grepping for them in the log file. Debugging also helps but it useful to have multiple options.

I tried out a lot to ease debugging Python doc tests and found the perfect solution for me you maybe like, too.
For Tryton scenario test construction and debugging I always use interlude. I just put a kind of breakpoint anywhere in the doc test scenario:

>>> import interlude; interact(locals())

When the test run reaches this command, it throws me out of the test into a Python interactive shell aka console. This console is in a similar state, as when I would have copy, paste and cleaned (remove indentation, >>>, ..., add line breaks) all the single commands from the doc test manually.
From this point I can try and error the next steps of the doc test directly in the console. Once I fiddled out the next test steps, I just copy and paste them from the console into the doc test script. No more worry about runtime errors because of wrong >>>, ... or indentations. After this, I move the above interlude breakpoint after my newly inserted test code and let it run.

2 Likes