julia-vscode / TestItemRunner.jl

Run Julia test items
MIT License
77 stars 11 forks source link

Can't export items from @testmodule modules #98

Open kenahoo opened 6 days ago

kenahoo commented 6 days ago

It would be very useful to export items from a @testmodule, but that appears not to be possible right now, correct?

I have the following in a file called test/test_test.jl:

@testmodule TestHelpers begin
    f(x, y) = x + y
    export f
end

@testitem "Test the tests" setup = [TestHelpers] begin
    # Try the exported function
    try
        f(1, 2) == 3
    catch e
        println("Error f(1, 2): ", e)
    end

    # Manually export it
    f = TestHelpers.f
    @test f(1, 2) == 3
end

When I run that from the VS Code testing pane, I get this output:

Error f(1, 2): UndefVarError(:f)
Test Summary:                        | Pass  Total  Time
.../test/test_test.jl:Test the tests |    1      1  0.0s

Is there some other technique besides this hacky workaround that I might have missed?

I'm using TestItemRunner v1.0.5 and VS Code 1.95.1. Thanks.

davidanthoff commented 6 days ago

Yes, agreed.

At the moment the modules that are listed in the setup section are imported into the test item module, but I think we should change that to using instead, and then your scenario should work.

Technically that is a breaking change, but given how new all of this is I think we can just do that.

kenahoo commented 6 days ago

Yeah, that sounds good to me. After all, for a @testmodule, if someone doesn't want stuff exported, they can just not export it. Thanks.