haf / expecto

A smooth testing lib for F#. APIs made for humans! Strong testing methodologies for everyone!
Apache License 2.0
663 stars 96 forks source link

Logging when running tests in parallel #480

Open Laxynium opened 8 months ago

Laxynium commented 8 months ago

Hi, following steps specified in section about test parallelism https://github.com/haf/expecto#about-test-parallelism I've created a few tests with logging inside to check how logging behaves.

module ExpectoLogging

open Expecto
open Expecto.Logging
open Expecto.Logging.Message

let logger = Log.create "Logger"

[<Tests>]
let tests =
    testList
        "all tests"
        ([ 1..10 ]
         |> List.map (fun i ->
             testCase $"failing test {i}" (fun () ->
                 logger.info (eventX "Info from test before {testNumber}" >> setField "testNumber" i)
                 Expect.isFalse true "Expected false")))

[<EntryPoint>]
let main argv =
    Tests.runTestsInAssemblyWithCLIArgs [] argv

I was expecting that logs from assertions and my custom logs would be grouped together and the order would be preserved, that is having 3 tests: "a"-> which logs "x" and then fails on assertion, "b" -> which logs "y" and then fails on assertion, "c" -> which logs "z" and then fails on assertion expected output would be something like -----test "a"------ "x" Expected false

-----test "c"------ "z" Expected false

----- test "b"------ "y" Expected false

However, my custom logs in output are disconnected from its wrapping testCase - they are not grouped. image

I'm not sure if I have missed something in documentation and this should be done differently to make it working. Do you have any hints how could I achieve this behaviour?

farlee2121 commented 8 months ago

I'm seeing the same issue.