1

I'm developing an API for communication with an FPGA. For testing the API I use Pytest. The API contains a logger that writes output to both the terminal and a file on disk. This all works fine. Now my problem is: when I run the pytests, some of my logger entries are not written to the logfile on disk. They are shown in the terminal though.

This is the output I see in the terminal when running a specific pytest:

[    INFO]  2022-11-25 09:35:08.943  Low Level API: Starting Interface with fpga_ip=127.0.0.1
[   DEBUG]  2022-11-25 09:35:08.946  Low Level API: Successfully pinged FPGA with IP 127.0.0.1
[    INFO]  2022-11-25 09:35:08.946  Sock Receiver: Instantiating Sock Receiver with ip=127.0.0.1, port=5005, snapshot_length=9050
[   DEBUG]  2022-11-25 09:35:08.956  Sock Receiver: Receiver Started
[   DEBUG]  2022-11-25 09:35:08.956  Low Level API: Reading defaults from file: pc/interface/defaults/standard.py
PASSED [100%][    INFO] 2022-11-25 09:35:08.957  Low Level API: Sending defaults to powerboard
[   DEBUG]  2022-11-25 09:35:08.957  Low Level API: Setting powerboard registers: {'vdda': 0, 'vddd': 0, 'vref': 20800}
[ WARNING]  2022-11-25 09:35:08.957  Low Level API: set_powerboard_registers: Method not implemented

And this is the content of the logfile on disk:

[    INFO]  2022-11-25 09:35:08.943  Low Level API: Starting Interface with fpga_ip=127.0.0.1 
[   DEBUG]  2022-11-25 09:35:08.946  Low Level API: Successfully pinged FPGA with IP 127.0.0.1
[    INFO]  2022-11-25 09:35:08.946  Sock Receiver: Instantiating Sock Receiver with ip=127.0.0.1, port=5005, snapshot_length=9050
[   DEBUG]  2022-11-25 09:35:08.956  Sock Receiver: Receiver Started
[   DEBUG]  2022-11-25 09:35:08.956  Low Level API: Reading defaults from file: pc/interface/defaults/standard.py
[    INFO]  2022-11-25 09:35:08.957  Low Level API: Sending defaults to powerboard

One can see that everything after PASSED [100%] (printout from Pytest) is omitted from the logfile on disk.

Running the same code outside of a pytest yields this result in the logfile on disk:

[    INFO]  2022-11-25 09:15:25.939  Low Level API: Starting Interface with fpga_ip=127.0.0.1
[   DEBUG]  2022-11-25 09:15:25.941  Low Level API: Successfully pinged FPGA with IP 127.0.0.1
[    INFO]  2022-11-25 09:15:25.941  Sock Receiver: Instantiating Sock Receiver with ip=127.0.0.1, port=5005, snapshot_length=9050
[   DEBUG]  2022-11-25 09:15:25.951  Sock Receiver: Receiver Started
[   DEBUG]  2022-11-25 09:15:25.951  Low Level API: Reading defaults from file: pc/interface/defaults/standard.py
[    INFO]  2022-11-25 09:15:25.952  Low Level API: Sending defaults to powerboard
[   DEBUG]  2022-11-25 09:15:25.952  Low Level API: Setting powerboard registers: {'vdda': 0, 'vddd': 0, 'vref': 20800}
[ WARNING]  2022-11-25 09:15:25.952  Low Level API: set_powerboard_registers: Method not implemented

Is it possible that Pytest deconstructs the API instance (and the logger therein) the moment it is convinced that the pytest was successful? How can it be that the logger output after the PASSED [100%] message is still displayed in the terminal, but not written to the logfile anymore?

0 Answers0