Infleqtion / client-superstaq

https://superstaq.readthedocs.io
Apache License 2.0
84 stars 19 forks source link

pytest doesn't return print statements when passing the "-s" flag #991

Closed pgoiporia closed 1 month ago

pgoiporia commented 2 months ago

What is happening?

Typically, for debugging tests, I will place print statements in my code and see what they return in the CLI. However, pytest doesn't seem to be returning these print statements anymore.

How can we reproduce the issue?

Add a print statement to any test.

What should happen?

It should return the print statement, but won't.

Environment

N/A

Any additional context?

N/A

bharat-thotakura commented 2 months ago

It looks like pytest-xdist just doesn't support the -s flag -- see discussion in https://github.com/pytest-dev/pytest-xdist/issues/354.

But there might be workarounds...

saeubank commented 1 month ago

Yeah it looks like the print statement needs to send the message to stderr for it to show. You can add something like print("Message here", file=sys.__stderr__) or you can run the test manually with pytest (without running ./checks/pytest_.py) to avoid the multi threaded tests.

We can also add an flag to run without xdist if needed, but I think the above solutions are easier.

bharat-thotakura commented 1 month ago

You can add something like print("Message here", file=sys.__stderr__)

I was using print("Message here", file=sys.stderr) initially which didn't seem to work, but can confirm print("Message here", file=sys.__stderr__) does work. Though as you mention, I usually just use pytest ... for specific debugging.

We can also add an flag to run without xdist if needed, but I think the above solutions are easier.

Requested in https://github.com/Infleqtion/client-superstaq/issues/990

richrines1 commented 1 month ago

linking @PalashGoiporia's proposal (which makes sense to me): https://github.com/Infleqtion/client-superstaq/issues/990#issuecomment-2231300487

(imo we should also treat the --incremental flag like passing in specific tests)