Skip to content

report test2json: report key=value subtest names as parameters - #46

Open
DzmitryHumianiuk wants to merge 2 commits into
feat/test2json-retriesfrom
feat/test2json-parameters
Open

DzmitryHumianiuk wants to merge 2 commits into
feat/test2json-retriesfrom
feat/test2json-parameters

Conversation

@DzmitryHumianiuk

Copy link
Copy Markdown
Member

Summary

Part of #26 (slice C6). Stacked on C5 → C4 → C3 → C2 → #29. The change itself only touches startTest.

Go has no parameterized tests, but table tests and benchmarks name their cases key=value. This PR reports those
pairs as ReportPortal test item parameters. Identity is not touched: testCaseId, uniqueId and codeRef stay
the full test name.

Changes

  • internal/commands/report_parameters.go: subtestParameters(name) derives parameters from a subtest's name
    relative to its parent:

    subtest name parameters
    n=1 n=1
    n=1#01 n=1 (the suffix Go adds to a repeated name is dropped)
    size=64/align=8 size=64, align=8
    tls=true,http2=false tls=true, http2=false
    list=a,b,c, path=a/b list="a,b,c", path="a/b" (the rest is not a pair, so it is part of the value)
    expr=a=b, k=, =v, url=http://x/y?q=1 none
    fails_when_n=1, max_size=10 none (see "key rule")
    plain, SetZero/string/size=16 none
  • Key rule: a letter followed by letters, digits, . or -. No _: the testing package turns spaces into
    underscores, so t.Run("fails when n=1") arrives as fails_when_n=1, and that must not become the parameter
    fails_when_n. The price is that max_size=10 gives no parameter.

  • Value rule: non-empty and without =.

  • A subtest also gets the parameters of the subtests it is nested in (cache=ram → pages=16 → plain all carry
    cache=ram), because the test case ran with all of them. Top-level tests never have parameters.

  • Fixture internal/commands/testdata/params/params.jsonl (real go test -json, go1.27.4), unit tests, an e2e
    test, README and skill.

Behaviour change

Items of subtests named key=value get parameters. Nothing else changes; items without such names are sent as
before (parameters is omitted).

Verification

  • go build ./... && go vet ./... && go test -race ./...: ok. Lint: 0 issues (also --build-tags e2e ./e2e/...).
  • Unit: TestSubtestParameters (24 names) and TestReportLaunch_SubtestParameters (the real stream: parameters
    and unchanged testCaseId of all 16 tests).
  • Live, ReportPortal 6.0.0 (demo): go test -tags e2e -count=1 -v -run SubtestParameters ./e2e/... →
    PASS TestReportTest2JSON_SubtestParameters (5.03s): the server returns the parameters on the items
    (n=1#01 → n=1; pages=16 and plain → cache=ram, pages=16; none for expr=a=b), and testCaseId is the
    full name. The server returns parameters in a different order than sent, so the test compares them as sets.

Investigation log

  1. Which naming conventions exist: scratchpad/wave/survey_params.sh greps the *_test.go files of the Go
    distribution (go1.27.4, $(go env GOROOT)/src) for Run("…=…") and Run(fmt.Sprintf("…=…")); output in
    scratchpad/wave/live/c6-survey.log: 433 literal and 71 formatted names with =.
    • The dominant form is one pair per name, nested with /: n=%d, size=64, Key=int64/Elem=int64,
      tableSize=%d/elems=%d/load=%0.3f, cache=ram/pages=%d.
    • The comma form exists but is rare: sameSubject=%t,sameKey=%t, DisableKeepAlive=%v,RequestClose=%v.
      Decision: accept it, but only when every comma-separated piece is a pair.
    • Keys in the survey: letters and digits, some with - (work-dur, tickers-per-P); none with _.
    • Mixed names exist (SetZero/%s/size=%d, gc=yes/ptrs=%v/%s). As nested t.Run calls each level is judged
      on its own; as one name with slashes they give nothing.
  2. What the testing package does to such names: scratchpad/wave/mkparams.sh → real stream. A repeated n=1
    becomes n=1#01; name=two words becomes name=two_words; a name with / stays one test
    (TestParams/tableSize=8/elems=4 has no TestParams/tableSize=8 parent).
  3. First version of the key pattern allowed _. The unit test with_n=1_inside/plain then produced the
    parameter with_n, which showed the sentence problem; hence the key rule above.
  4. Parameters are derived from the name relative to the parent the reporter found (parentOf), not by splitting
    the full test name at /: url=http://x/y split at / would give the wrong pair url=http:.
  5. testCaseId is set explicitly by the reporter (reporter.go, startTest), so the server does not derive it
    from the parameters; confirmed by the e2e assertion.

Open questions

  • Keys with _ (max_size=10) are not recognised. Allowing them needs another way to tell a pair from a
    sentence.
  • Inheriting the parents' parameters is a choice; without it plain under cache=ram/pages=16 has none.

Not verified

  • How the UI shows parameters on nested steps.
  • Benchmarks (go test -bench -json): their names end in -GOMAXPROCS (size=64-8), which would end up in the
    value. report test2json does not handle benchmark events today.

🤖 Generated with Claude Code

A subtest named after the table test convention 'key=value' gets the pair
as a test item parameter. Several pairs in one name are separated by '/'
or ',', and a subtest also gets the parameters of the subtests it is
nested in. Only names that consist of such pairs count: keys are letters,
digits, '.' and '-' (no '_', which is what the testing package makes of a
space, so 'fails_when_n=1' is a sentence), values are non-empty and have
no '='. The '#1' suffix of a repeated name is not part of the value.

The test case ID, unique ID and code reference stay the full test name.

Part of #26.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants