Subunit Trace

Trace a subunit stream in reasonable detail and high accuracy.

class stestr.subunit_trace.DiscardAttachments[source]

Swallow the file attachment events of a subunit stream.

The runner streams carry the stdout/stderr of the tests as file attachments, in chunks without a test id. Their relevant content is already rendered by the per-test output of the failing tests, and tests often print unstructured data (e.g. generated resource names) without trailing newlines, which catted verbatim would corrupt the rendering of the next result line. Dropping the raw chunks keeps the output aligned, like the subunit2pyunit pipelines do.

status(test_id=None, test_status=None, test_tags=None, runnable=True, file_name=None, file_bytes=None, eof=False, mime_type=None, route_code=None, timestamp=None)[source]

Inform the result about a test status.

Parameters:
  • test_id – The test whose status is being reported. None to report status about the test run as a whole.

  • test_status –

    The status for the test. There are two sorts of status - interim and final status events. As many interim events can be generated as desired, but only one final event. After a final status event any further file or status events from the same test_id+route_code may be discarded or associated with a new test by the StreamResult. (But no exception will be thrown).

    Interim states:
    • None - no particular status is being reported, or status being reported is not associated with a test (e.g. when reporting on stdout / stderr chatter).

    • inprogress - the test is currently running. Emitted by tests when they start running and at any intermediary point they might choose to indicate their continual operation.

    Final states:
    • exists - the test exists. This is used when a test is not being executed. Typically this is when querying what tests could be run in a test run (which is useful for selecting tests to run).

    • xfail - the test failed but that was expected. This is purely informative - the test is not considered to be a failure.

    • uxsuccess - the test passed but was expected to fail. The test will be considered a failure.

    • success - the test has finished without error.

    • fail - the test failed (or errored). The test will be considered a failure.

    • skip - the test was selected to run but chose to be skipped. e.g. a test dependency was missing. This is purely informative- the test is not considered to be a failure.

  • test_tags – Optional set of tags to apply to the test. Tags have no intrinsic meaning - that is up to the test author.

  • runnable – Allows status reports to mark that they are for tests which are not able to be explicitly run. For instance, subtests will report themselves as non-runnable.

  • file_name – The name for the file_bytes. Any unicode string may be used. While there is no semantic value attached to the name of any attachment, the names ‘stdout’ and ‘stderr’ and ‘traceback’ are recommended for use only for output sent to stdout, stderr and tracebacks of exceptions. When file_name is supplied, file_bytes must be a bytes instance.

  • file_bytes – A bytes object containing content for the named file. This can just be a single chunk of the file - emitting another file event with more later. Must be None unleses a file_name is supplied.

  • eof – True if this chunk is the last chunk of the file, any additional chunks with the same name should be treated as an error and discarded. Ignored unless file_name has been supplied.

  • mime_type – An optional MIME type for the file. stdout and stderr will generally be “text/plain; charset=utf8”. If None, defaults to application/octet-stream. Ignored unless file_name has been supplied.

class stestr.subunit_trace.DynamicProgress(total_tests)[source]

Compute the progress annotation of a dynamic scheduler run.

With –dynamic-progress, each test line of the run output is annotated with the progress of the run: the number of tests already completed (the test on the line included), the corresponding percentage and a rough ETA extrapolating the average duration of the completed tests to the remaining ones, e.g. [ 42/312 (13.5%) Time: 00:00:33, ETA: ~00:08:53].

The numbers are computed from the completion timestamps the subunit stream carries, so the annotation needs no shared state with the workers of the run. The elapsed time and the ETA are unknown until a first test completed.

Parameters:

total_tests (int) – The total number of tests scheduled for the run.

elapsed_time()[source]

Render the time elapsed since the first test started.

record_start(timestamp=None)[source]

Account the start timestamp of a test of the run.

record_stop(timestamp=None)[source]

Account a completed test and its completion timestamp.

class stestr.subunit_trace.DynamicProgressReporter(progress, stream=None)[source]

Emit the progress annotation of a run on stderr, per test.

Used on the raw subunit stream path (–subunit): the per-test lines are rendered by the consumer of the stream, which stestr cannot annotate, so the same annotation as the subunit-trace one is written to stderr for every completed test, interleaved with the output of the pipeline.

Parameters:
  • progress – The DynamicProgress instance accounting the run.

  • stream – The stream the annotations are written to, defaults to sys.stderr.

status(test_id=None, test_status=None, test_tags=None, runnable=True, file_name=None, file_bytes=None, eof=False, mime_type=None, route_code=None, timestamp=None)[source]

Inform the result about a test status.

Parameters:
  • test_id – The test whose status is being reported. None to report status about the test run as a whole.

  • test_status –

    The status for the test. There are two sorts of status - interim and final status events. As many interim events can be generated as desired, but only one final event. After a final status event any further file or status events from the same test_id+route_code may be discarded or associated with a new test by the StreamResult. (But no exception will be thrown).

    Interim states:
    • None - no particular status is being reported, or status being reported is not associated with a test (e.g. when reporting on stdout / stderr chatter).

    • inprogress - the test is currently running. Emitted by tests when they start running and at any intermediary point they might choose to indicate their continual operation.

    Final states:
    • exists - the test exists. This is used when a test is not being executed. Typically this is when querying what tests could be run in a test run (which is useful for selecting tests to run).

    • xfail - the test failed but that was expected. This is purely informative - the test is not considered to be a failure.

    • uxsuccess - the test passed but was expected to fail. The test will be considered a failure.

    • success - the test has finished without error.

    • fail - the test failed (or errored). The test will be considered a failure.

    • skip - the test was selected to run but chose to be skipped. e.g. a test dependency was missing. This is purely informative- the test is not considered to be a failure.

  • test_tags – Optional set of tags to apply to the test. Tags have no intrinsic meaning - that is up to the test author.

  • runnable – Allows status reports to mark that they are for tests which are not able to be explicitly run. For instance, subtests will report themselves as non-runnable.

  • file_name – The name for the file_bytes. Any unicode string may be used. While there is no semantic value attached to the name of any attachment, the names ‘stdout’ and ‘stderr’ and ‘traceback’ are recommended for use only for output sent to stdout, stderr and tracebacks of exceptions. When file_name is supplied, file_bytes must be a bytes instance.

  • file_bytes – A bytes object containing content for the named file. This can just be a single chunk of the file - emitting another file event with more later. Must be None unleses a file_name is supplied.

  • eof – True if this chunk is the last chunk of the file, any additional chunks with the same name should be treated as an error and discarded. Ignored unless file_name has been supplied.

  • mime_type – An optional MIME type for the file. stdout and stderr will generally be “text/plain; charset=utf8”. If None, defaults to application/octet-stream. Ignored unless file_name has been supplied.

stestr.subunit_trace.cleanup_test_name(name, strip_tags=True, strip_scenarios=False)[source]

Clean up the test name for display.

By default we strip out the tags in the test because they don’t help us in identifying the test that is run to it’s result.

Make it possible to strip out the testscenarios information (not to be confused with tempest scenarios) however that’s often needed to indentify generated negative tests.

stestr.subunit_trace.find_worker(test)[source]

Get the worker number.

If there are no workers because we aren’t in a concurrent environment, assume the worker number is 0.

stestr.subunit_trace.print_attachments(stream, test, all_channels=False, show_binary_attachments=False)[source]

Print out subunit attachments.

Print out subunit attachments that contain content. This runs in 2 modes, one for successes where we print out just stdout and stderr, and an override that dumps all the attachments.

stestr.subunit_trace.print_fails(stream)[source]

Print summary failure report.

stestr.subunit_trace.print_full_output(stdout, start_times, stop_times, post_fails, no_summary)[source]

Print output plus edge case validation

stestr.subunit_trace.worker_tag(worker, worker_count=1)[source]

Render the worker prefix of a result line.

The number is right-aligned on the width of the largest worker number of the run, so that the result lines line up: a run with less than 10 workers uses one character, more than 99 three.