Test reports¶
VS Code Any LSP editor CLI MCP Beta
Added in version 0.37.0.
Every key, with its type and default: [test_reports].
The [test_reports] section holds the settings of
sphinx-test-reports,
which turns JUnit-style XML test reports into needs.
sphinx-test-reports (2.0 and later) and its converter,
the test-reports build needs command of the ub-test-reports package,
read the same section, so one ubproject.toml describes the project to all three tools.
When the section is present — even as an empty [test_reports] table —
ubCode adds the three sphinx-test-reports need types and the fields their needs carry
to the project’s needs configuration,
so a needs.json written by the converter imports with nothing else declared.
The section’s presence is the switch:
ubCode does not read conf.py, so a project that loads sphinx-test-reports there
needs a [test_reports] table (an empty one will do) for ubCode to add the same types and fields —
or the extension’s name in [parse] extensions,
extensions = ["sphinx_test_reports"], which means the same as an empty table when there is none
(its old name, sphinxcontrib.test_reports, is read as the new one and reported at information level).
"sphinx_test_reports" = false in [parse.extensions] switches the extension off and keeps the section,
including one a project inherits through extend;
an explicit false under either name beats an explicit true under the other.
Switched off, the extension is withdrawn whole, as an unloaded Sphinx extension is:
its need types and fields are not added,
so a needs.json written by the converter imports with Invalid need type;
its five directives still parse with their options,
and each renders as a labelled placeholder with a directive.extension_disabled warning
naming the entry to set back to true —
unless a [[needs.types]] entry or a [parse.extend_directives] entry of the same name owns it,
as it then does.
The switch itself is reported once, at information level (config.test_reports_switched_off).
The five directive names belong to sphinx-test-reports while it is switched on:
a [[needs.types]] entry whose directive is test-file, test-suite, test-case,
test-results or test-env
keeps its need type, but .. test-case:: reads a test report,
and the configuration says so (config.conflicting_directive_registration).
Give such a type another directive.
Switched off, or without the section, the project’s type owns the name.
The directives are read under their own spelling only:
.. Test-Case:: is not a test-report directive (it keeps the generic placeholder),
where a Sphinx build stops on it.
Note
Of the sphinx-test-reports directives,
test-file, test-suite and test-case are supported, one need each,
and a test-file’s :auto_suites: / :auto_cases: expansion into a need per suite and case,
and so are the test-results and test-env tables
and the test-report directive with its report template:
see Test reports: the directives.
ubCode reads the section, adds the vocabulary, and checks the settings.
Minimal example¶
[test_reports]
extra_options = ["TestType"]
[test_reports.build.needs]
project = "demo"
link_properties = { PartiallyVerifies = "links" }
This is enough to import the converter’s output:
the testcase need type, the test-report fields and the TestType field come from the section,
and the converter reads extra_options and link_properties from the same file.
What the section adds¶
Need types.
The file, suite and case entries each add a need type,
named by the entry’s type
(testfile, testsuite and testcase by default),
with its name as the title and its prefix, color and style.
They are added after the project’s own types —
the default types, or the [[needs.types]] the project declares instead —
and never re-enable a default type the project replaced.
Each also makes a need directive of that name (.. testcase::), as in a Sphinx build.
ubc agent config-validate and ubc agent doctor count them as declared types,
so a [workflow] or link coverage rule can name them without a [[needs.types]] entry,
and expect no [workflow] stage to produce them (no type_unproduced warning),
one an entry of the project narrows included, bare or with a title and a prefix.
A type of the section named as a default type the project keeps is that default type, used unchanged,
which a stage is expected to produce as any other.
An entry of the project naming one narrows it.
A [needs.types.<type>] entry naming one of these types — with a title and a prefix, or bare, with neither —
narrows the section’s type rather than replacing it:
the keys the entry gives win,
the title, prefix, color and style it leaves out are the section’s,
and its fields, links, inherits,
back_links (incoming links),
id_regex (the ids of a type)
and a field’s severity (Severity)
apply as on any type the project declares,
so a rule can be attached to the test cases themselves:
[test_reports]
# test cases gain a link type of their own, derived from the project's tests
[needs.types.testcase.links.evidence_for]
derive = { kind = "links", join = { field = "case_name", equals = "case_name" }, where = "type == 'test'" }
# `case_name` is a field of the test cases alone: the project's tests carry it too
[needs.types.test.fields.case_name]
The entry’s id_regex checks every id of the type’s needs, the ones the test-report directives write and generate included
(a test-case without :id:, each case of an :auto_cases: expansion, under either id scheme):
a need whose id it refuses is kept and reported as needs.id_regex, naming the pattern and the type
(a Sphinx build does not create it).
A field the entry declares starts from the section’s declaration and may only narrow it, as any type’s declaration does:
the section’s fields are nullable and carry no schema keyword, so no key the entry gives widens one,
and another type is refused (config.type_conflict), that field’s entry ignored.
A bare entry declares no type: the default types are kept beside it, as beside a bare entry naming a default type,
and the narrowed type stands where the section adds it, after the project’s own types.
An entry with a title and a prefix declares the project’s types, as any such entry does,
and the type stands where the entry is given.
Without the section, a bare testcase entry names no type and is ignored, with a config.need_type warning
that names derive_by_type as the spelling for a type the project does not declare.
A default type of the same name (when the project declares no type) is used unchanged,
and if its title, prefix, color or style differs from the section’s,
config.test_reports_type_declared names both values.
Fields. Every field a test-report need carries is added as an extra field:
Field |
Type |
Holds |
|---|---|---|
|
string |
the test’s suite, name, parameter and class |
|
string |
the result ( |
|
string |
the execution time in seconds, as the report gives it |
|
string |
the test’s source in the remote repository |
|
integer |
the counters of a test-file or test-suite need, so |
|
string |
the report path and the test’s source location, under the names
|
each |
string |
the test property of that name |
Each field is declared on the need types that carry it.
suites on the test-file type;
cases, passed, skipped, failed and errors on the test-file and test-suite types;
suite on the test-suite and test-case types;
the other test-case fields and the source location on the test-case type;
the report path and every extra_options name on all three —
and on the types that inherit from them.
An extra_options name that is a core field of every need (style, layout)
stays a field of every need type.
On every other need type the field is absent (null),
and a value set there is ignored and reported as needs.undeclared_for_type,
as for a field a [needs.types.<type>.fields.<name>] entry declares alone.
A project type that should carry one names it in its own entry,
which declares the field there too (an entry refused with config.type_conflict declares nothing);
the tr_link-style join on case_name between the project’s own test needs and the test cases needs it:
[needs.types.test.fields.case_name]
A source location or a parameter the report does not give is null, not ""
(pytest’s default JUnit format gives no file or line),
so a filter for a case with no source line is case_line is None (or not case_line), not case_line == ''.
A field the project already declares under [needs.fields] (or in [needs] extra_options)
is that field, on every need type, as declared.
Declared with another type, it is kept too,
and config.test_reports_field_type_mismatch says the test-report values may not fit it —
except a numeric field declared as a type its values fit:
a number (time, [needs.fields.time] schema = { type = "number" })
or a number or an integer (the source-line field, case_line).
Their values are numeric strings, which the import converts, so time > 0.1 compares numbers;
time declared as an integer is reported, since its values are fractional seconds.
Any other string field the section adds, declared as a number, is reported: its values cannot convert,
and every imported need would be refused.
The same code reports a field the section adds whose name the project uses for a link type.
Some names cannot be extra options.
These extra_options names are ignored and reported as config.test_reports_extra_option_reserved,
as sphinx-test-reports refuses them (where it ends the build):
a field a test-report directive sets itself:
id,type,title,content,links,tags,statusandcollapseon every test need,suiteson a test file,cases,passed,skipped,failedanderrorson a test file or suite,suiteon a test suite or case, andcase,case_name,case_parameter,classname,resultandtimeon a test case (the finding names the first oftest-file,test-suiteandtest-casethat sets it);the report path and source-location fields, under the names
file_option,source_file_optionandsource_line_optionchoose (file,case_fileandcase_lineby default);a core field of Sphinx-Needs that no option can set, such as
docname,lineno,sections,signature,parts,is_external,external_urlortype_name;an empty name, or a link type.
ubCode also refuses var (the variant data namespace)
and a core field that is not a string, such as hide.
A directive option matches an extra option by any case
(:TestType: and :testtype: both set the TestType field, in reStructuredText and MyST),
so the first three kinds above are refused in any case
(a field a directive sets, a report path or source-location field, a core field no option can set):
Result is refused as result is.
The other refusals compare the name as written:
Var is an ordinary name,
and Hide, or Verifies beside a link type verifies, is kept,
with a config warning that the two names differ only in case.
style stays allowed (only a test case sets it),
as do result_text and remote_url, the converter’s own fields.
With style listed, though, a test-case that writes :style:, or whose report case has a style property,
has that value replace the case’s own tr_<result> style, without a finding,
where sphinx-test-reports refuses the need
(“[‘style’] given by the report or the configuration, and set by the directive itself”).
A refused name — any of the above — is left out of the section entirely:
it is not a field, and a report property of that name is not read.
Unless a directive has it as an option of its own anyway (id, status, tags, links, collapse,
and file, suite, case or classname where that directive takes it),
it is no option of the test-report directives either,
so a directive that writes it (:result: on a test-case, :hide:, :docname:)
is refused for an unknown option (block.directive_unknown_option) and makes no need.
The fields are added before the [needs] features that name a field are read,
so [needs.global_options], string links
and card-layout field: elements can name them with nothing else declared.
Link fields are not added.
links always exists;
any other field named as a property_link_types target must be a declared link type
([needs.links]),
and config.test_reports_link_target_undeclared reports one that is not.
(A Sphinx build’s test-report directives stop there with InvalidNeedException.)
ubc config shows the types and fields the section added, under needs,
and the resolved section itself under test_reports.
Lines of pytest reports¶
A test case’s source line (case_line) is the line of the test in its file, counted from 1,
wherever the reader knows what the report’s line counts from:
for a pytest test, the line of its first decorator, or of its def.
pytest’s own JUnit writer counts from 0, Google Test and the ub-test-reports pytest plugin from 1,
so the base is decided per <testsuite> (a nested suite inherits it), in this order:
a suite property
<property name="ub_test_reports:line_base" value="1"/>(or"0"), the mark the ub-test-reports plugin writes, gives it; any other value is no mark;else a test case carrying both of Google Test’s
statusandresultattributes counts from 1, whateverline_basesays;else
line_base = 0orline_base = 1gives it;else a suite named
pytest, or any suite of a report whose root is<testsuites name="pytest tests">(pytest 8.4.0 and later), counts from 0, so its lines are read one more;else the line is read as written.
A line of -1 (or below) means “no line” and is never moved,
and a line 0 counted from 0 is line 1.
A report that already counts from 1 but carries no mark —
written by an earlier ub-test-reports or sphinx-test-reports pytest plugin, say — is read one line late;
regenerate it with the current plugin, or set line_base = 1.
Options¶
- file
Type:
tableorarrayof 6 strings (default:directive = "test-file",type = "testfile",name = "Test-File",prefix = "TF_",color = "#ffffff",style = "node")The test-file directive and the need type it creates. Two spellings are accepted: a table, where each key left out takes its default,
[test_reports.file] type = "testfile" prefix = "TF_"
or the six strings in the order
directive,type,name,prefix,color,style, astr_fileis written in aconf.py:[test_reports] file = ["test-file", "testfile", "Test-File", "TF_", "#ffffff", "node"]
An array of any other length, a table key other than these six, or a value that is not a string is an error. The table is the clearer spelling, since six strings in a row cannot be told apart.
Renaming the
directiveis not supported yet: the setting is kept, the directive keeps its default name, andconfig.test_reports_rename_unsupportedsays so.- suite
Type:
tableorarrayof 6 strings (default:test-suite,testsuite,Test-Suite,TS_,#cccccc,folder)The test-suite directive and need type, spelled as
fileis.- case
Type:
tableorarrayof 6 strings (default:test-case,testcase,Test-Case,TC_,#999999,rectangle)The test-case directive and need type, spelled as
fileis. When[test_reports.build.needs]is present, itstypemust equal that table’sneed_type(each compared at its default when unset): otherwise the configuration is refused, because the converter’sneeds.jsonand the build would describe different need types.- file_option
Type:
string(default:"file")The need field holding the path of the test report.
- source_file_option
Type:
string(default:"case_file")The need field holding the test’s source file.
- source_line_option
Type:
string(default:"case_line")The need field holding the test’s line in its source file.
The three field names must each be a field of their own: naming a field every test-case need already has (
case,result,status,links, …), or two of them naming the same field, refuses the configuration. An empty string means the default.- rootdir
Type:
string(default: the source directory)The directory relative report paths are read from. A relative path is taken from the directory of the
ubproject.tomlthat sets it. Unset, ubCode uses[source] dir(or theubproject.toml’s own directory when that is unset); a Sphinx build uses its configuration directory — the one holdingconf.py— instead. Set it wheneverconf.pyis not in the source directory, so that both tools read reports from the same place.- report_template
Type:
string(default: the template shipped with sphinx-test-reports)The template a
test-reportdirective renders (A whole report: test-report). A relative path is taken from the directory of theubproject.tomlthat sets it (a-cvalue from the working directory, as every-cpath is). The template’s{template_path}names it relative to theubproject.tomlthat set it — the project’s ownubproject.tomlfor a-cvalue — so a page reads the same wherever it is built. The path is trusted, as the configuration is: a template outside the project root is read. Unset or"", the template shipped with ubCode — sphinx-test-reports’ own, listing every case. ubCode formats a template with{key}for its ten keys and the escapes{{and}}, and nothing else of Python’sstr.format; A whole report: test-report lists the keys.- suite_id_length
Type:
integer(default:3)How many characters of a suite’s hash an automatically generated suite id keeps: the id of each suite need of a
test-file’s:auto_suites:expansion (A need per suite and per case). Raise it whenneeds.test_report_duplicate_idreports two suite names with one id.- case_id_length
Type:
integer(default:5)How many characters of a test case’s hash an automatically generated case id keeps: the id of each case need of an
:auto_cases:expansion, unlessdeterministic_case_idsis on.Both lengths are non-negative integers; a negative one is refused (sphinx-test-reports accepts it).
- import_encoding
Type:
string(default:"utf8")The text encoding of the report template.
- extra_options
Type:
array of strings(default:[])Test properties that become need fields: each name is added as a string field, and a
<property>of that name is copied into it. Some names cannot be extra options (which).- property_link_types
Type:
tableof strings (default:{})Test properties whose values become links, as a table from a property name to the link field it fills:
[test_reports] property_link_types = { PartiallyVerifies = "links" }
A comma-separated property value such as
"REQ_1, REQ_2"gives one link per id.linksis always available; any other target must be a declared link type.- json_mapping
Type:
table(default: the sphinx-test-reports mapping)How the fields of a JSON test report are found. Accepted and kept, but JSON test reports are not read yet: a directive whose
:file:ends in.jsonreportsneeds.test_report_json_unsupported.- deterministic_case_ids
Type:
boolean(default:false)Whether automatically generated test-case ids use the deterministic scheme,
<type>__<class>__<name>_<five letters>(the one the converter always writes, such astestcase__MathTest__Addition_hcuyy), instead of the legacy hashed one — for atest-casewithout:id:and for each case need of an:auto_cases:expansion.- line_base
Type:
"auto",0or1(default:"auto")What a JUnit report’s
linecounts from, where the report does not say so itself (Lines of pytest reports)."auto"counts pytest’s own reports from 0 and reads any other report’s lines as written;0or1sets the base of a suite that has no mark, of its own or from an enclosing suite, for its test cases that are not shaped as Google Test’s. Any other value — the string"1",true,1.0— refuses the configuration. sphinx-test-reports reads the same setting astr_line_base.
[test_reports.build.needs]¶
How test-reports build needs writes a needs.json.
The converter reads this table; ubCode checks it, so a mistake is caught by whichever tool reads the file first.
- project
Type:
string(default:"")The
projectwritten into theneeds.json.- version
Type:
string(default:"1.0")The version the needs are written under.
- need_type
Type:
string(default:"testcase")The need type every test case gets. Must equal the
typeofcase.- tags
Type:
array of strings(default:[])Tags added to every test-case need.
- link_properties
Type:
tableof strings (default: unset)The converter’s spelling of
property_link_types. ubCode reads it as an alias, deprecated from the start: whenproperty_link_typesis unset,link_propertiesis used in its place; when both are set and differ,property_link_typesis used andconfig.test_reports_link_properties_differreports the difference. sphinx-test-reports is merging the two keys intoproperty_link_types(sphinx-needs#2055); until a converter release reads that key, write the mapping here, where the converter reads it too. Both names in each pair must be non-empty.- remote_url
Type:
string(default:"")The repository URL the converter makes source links from.
- commit
Type:
string(default:"")The commit the source links point at. A CI job usually keeps
remote_urlin the file and passes the commit on the converter’s command line (--commit), which is why ubCode does not ask for the two together.- url_pattern
Type:
string(default:"{base}/blob/{commit}/{file}#L{line}")The source-link pattern, made from the placeholders
{base},{commit},{file}and{line}.
ubCode never makes a source link itself.
It checks url_pattern with the converter’s own rule —
a pattern that cannot make a link is wrong whatever the command line passes —
and reports a problem as config.test_reports_url_pattern, a warning, where the converter refuses to run.
Whether remote_url and commit are given together is the converter’s to check, with its flags in hand.
How the section is read¶
- Unknown keys
A key ubCode does not read, in
[test_reports],[test_reports.build]or[test_reports.build.needs], is ignored and reported asconfig.test_reports_unknown_key, one finding per table naming every such key and the supported ones. The rest of the table is read, so aubproject.tomlwritten for a newer sphinx-test-reports still loads. sphinx-test-reports reports unknown keys the same way.- Wrong types
A known key of the wrong type —
case_id_length = "5",extra_options = "TestType"— fails the configuration, with the position of the value. So do the two rules above that span keys: the field names offile_option,source_file_optionandsource_line_option, andcase’s type againstneed_type. The messages for thefile,suiteandcasespellings and for the two rules are sphinx-test-reports’ own; other keys report the configuration reader’s own type message.- Paths
rootdirandreport_templateare taken from the directory of theubproject.tomlthat sets them, also when it is a file another configuration extends; a-cvalue is taken from the working directory.- Shared files
Through
extendthe section is inherited key by key, and afile/suite/casetable folds key by key too (a six-string array is one value). sphinx-test-reports and its converter read only the nearestubproject.toml, so repeat the section there when the project is also built with Sphinx.- Precedence
A
-coverride (orUBCODE_CONFIG_OVERRIDE) wins over theubproject.toml, which wins over the default:$ ubc check -c 'test_reports.case_id_length = 8'
A Sphinx build reads the same section with
-Din place of-c, and atr_*value in itsconf.pybetween the two; ubCode reads noconf.py, so move such values into the section.
The section’s eight findings are listed with the other configuration codes in Linting, and The [test_reports] section lists where ubCode and a Sphinx build read the section differently.