scancode.io
scancode.io copied to clipboard
Unwanted log output while running tests
Following https://github.com/nexB/scancode.io/pull/1078, the following log output is now printed to the console.
test_scanpipe_management_command_mixin_create_project_pipelines (scanpipe.tests.test_commands.ScanPipeManagementCommandMixinTest) ... ok
Project my_project created with work directory /tmp/tmp4piju9ta/projects/my_project-65651b5e
Project my_project created with work directory /tmp/tmp4piju9ta/projects/my_project-e2e57bc8
Start the load_inventory pipeline execution...
load_inventory successfully executed on project my_project
Project other_project created with work directory /tmp/tmp4piju9ta/projects/other_project-5b527efa
Project my_project created with work directory /tmp/tmp4piju9ta/projects/my_project-52cf6322
Files copied to the project inputs directory:
- test_commands.py
- test_models.py
Project my_project created with work directory /tmp/tmp4piju9ta/projects/my_project-d3c68f42
Project my_project created with work directory /tmp/tmp4piju9ta/projects/my_project-c5b84707
@tdruez
I tried using contextlib.redirect_stdout to redirect stdout, but it didn't seem to work when I did:
out = StringIO()
with redirect_stdout(out):
project = self.create_project_command.create_project(name="my_project", stdout=out)
The call to command.stdout.write
, for example https://github.com/nexB/scancode.io/blob/main/scanpipe/management/commands/init.py#L445, is still written to the terminal and not captured in the StringIO buffer. If I did something like this:
with redirect_stdout(out):
print("1234")
The string "1234" is captured in out
.
I ended up passing stdout and stderr as kwargs into the command mixin functions and have an if statement to determine if we have stdout
or stderr
passed into the argument and if so, to write to that instead of command.stdout
or command.stderr
(https://github.com/nexB/scancode.io/commit/b21278e9b4ef9683acc9635f5a8d97827ff53236#diff-3bb6288a7690ee9b12d230b3b4d8290cbd8034a8406c34e44e6ce8653115138eR323) This works but it doesn't look great. I'd like to use redirect_stdout
, but I'm not sure why the output is not captured when we use command.stdout.write
.
Fixed in https://github.com/nexB/scancode.io/pull/1256