# Strange text output from running Julia tests

**URL:** <https://discourse.julialang.org/t/strange-text-output-from-running-julia-tests/122379>\
**Category:** New to Julia\
**Tags:** question\
**Created:** [November 7, 2024, 12:13pm UTC](https://discourse.julialang.org/t/strange-text-output-from-running-julia-tests/122379 "2024-11-07T12:13:45Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![world-peace](https://avatars.discourse-cdn.com/v4/letter/w/9f8e36/32.png) [@world-peace](https://discourse.julialang.org/u/world-peace)\
**Post date:** [November 7, 2024, 12:13pm UTC](https://discourse.julialang.org/t/strange-text-output-from-running-julia-tests/122379/1 "2024-11-07T12:13:45Z")

</div>

I’m getting this somewhat mysterious output when running some of my Julia tests. I don’t recall seeing this yesterday.

```julia
Test.DefaultTestSet("someModule", Any[], 8, false, false, true, 1.730981062858112e9, 1.730981062860939e9, false, "/home/user/path/test/someModule.jl")

```

Sorry for the “dumb” question - but what is this? What causes this text to be printed? Where does it come from?

---

<div class="post-metadata">

**Author:** ![giordano](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/giordano/32/2166_2.png) [@giordano](https://discourse.julialang.org/u/giordano)\
**Post date:** [November 7, 2024, 12:17pm UTC](https://discourse.julialang.org/t/strange-text-output-from-running-julia-tests/122379/2 "2024-11-07T12:17:41Z")

</div>

That’s the display of a testset:

```julia
julia> @testset begin
           @test true
       end;
Test Summary: | Pass Total Time
test set | 1 1 0.0s

julia> @testset begin
           @test true
       end
Test Summary: | Pass Total Time
test set | 1 1 0.0s
Test.DefaultTestSet("test set", Any[], 1, false, false, true, 1.730981704137089e9, 1.73098170413711e9, false, "REPL[4]")

```

Note that in the first case I put a semicolon to [suppress the display in the REPL](https://docs.julialang.org/en/v1/stdlib/REPL/#The-Julian-mode). That said, hard to tell why are you seeing that without knowing what you’re doing exactly in the first place.

---

<div class="post-metadata">

**Author:** ![world-peace](https://avatars.discourse-cdn.com/v4/letter/w/9f8e36/32.png) [@world-peace](https://discourse.julialang.org/u/world-peace)\
**Post date:** [November 7, 2024, 1:32pm UTC](https://discourse.julialang.org/t/strange-text-output-from-running-julia-tests/122379/3 "2024-11-07T13:32:52Z")

</div>

Here’s a further strange observation.

Adding the semicolon has no effect.

However, adding the semicolon, followed by

```julia
println("DONE")

```

does prevent `Test.DefaultTestSet(...)` from being printed. However, of course, it will now print `DONE` instead.

---

<div class="post-metadata">

**Author:** ![mbauman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mbauman/32/31082_2.png) [@mbauman](https://discourse.julialang.org/u/mbauman)\
**Post date:** [November 7, 2024, 2:01pm UTC](https://discourse.julialang.org/t/strange-text-output-from-running-julia-tests/122379/4 "2024-11-07T14:01:44Z")

</div>

It really depends on how you’re running the tests. The key thing to note is that — just like you’ve seen in other threads — Julia is an expression-based language and _every expression_ has a return value. That value might be the thing called `nothing` (which doesn’t display itself at all), or it might be something like a TestSet, which prints as it’s running and then can display a representation of the object.

The semicolon is just a “flag” to tell the REPL not to display the object that’s returned. So the place to put it is literally on the REPL input line. If you’re running the tests with an include, that’s:

```Julia-repl
julia> include("test/runtests.jl");
Test Summary: | Pass Total Time
test set | 1 1 0.0s

julia> # ^^ Look, no extra output

```

---

<div class="post-metadata">

**Author:** ![goerz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/goerz/32/3269_2.png) [@goerz](https://discourse.julialang.org/u/goerz)\
**Post date:** [November 7, 2024, 2:45pm UTC](https://discourse.julialang.org/t/strange-text-output-from-running-julia-tests/122379/5 "2024-11-07T14:45:41Z")

</div>

I usually [put the value `nothing` on the last line of my `runtests.jl`](https://github.com/JuliaQuantumControl/QuantumControl.jl/blob/bf7a15e9c9d042ead4e7afa439a875dec631092c/test/runtests.jl#L102) to avoid exactly this output

---

<div class="post-metadata">

**Author:** ![world-peace](https://avatars.discourse-cdn.com/v4/letter/w/9f8e36/32.png) [@world-peace](https://discourse.julialang.org/u/world-peace)\
**Post date:** [November 7, 2024, 3:13pm UTC](https://discourse.julialang.org/t/strange-text-output-from-running-julia-tests/122379/6 "2024-11-07T15:13:25Z")

</div>

Thanks, I’ll just do the same thing.

If you have _nested_ `@testset`s, do you need to put `return nothing` at the end of each, or just at the end of the _outer_ test set?

I know I can easily test this but since I haven’t been seeing the same behavior as expected (because I don’t know exactly what to expect) I’m hoping you can tell me which of the two cases it is.

---

<div class="post-metadata">

**Author:** ![goerz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/goerz/32/3269_2.png) [@goerz](https://discourse.julialang.org/u/goerz)\
**Post date:** [November 7, 2024, 3:26pm UTC](https://discourse.julialang.org/t/strange-text-output-from-running-julia-tests/122379/7 "2024-11-07T15:26:25Z")

</div>

Generally, you’ll only need it after the outer testset. Or, if things are split over multiple files, potentially at the end of every file.

The point is that the REPL prints the result of any top-level expression it evaluates. If that expression is an `include`, and you don’t want the result of the last expression in the included file to be printed, you can make that last expression in the file be `nothing`.

This really goes back to your earlier confusion

> [@Why does append!(df1, df2) return a DataFrame, as well as modify the argument df1?](https://discourse.julialang.org/t/why-does-append-df1-df2-return-a-dataframe-as-well-as-modify-the-argument-df1/122329/3):
>
> Functions usually either modify one of their arguments, or do not modify their arguments and return a new value.

which is just completely false in Julia. All expressions in Julia (including `include`) return something. Moreover, the convention is for things to return the last expression from their “body”. There does not need to be an explicit `return` statement, and things return `nothing` only if they _explicitly_ return `nothing` (or the last expression they contain returns `nothing`).

In this case putting `nothing` at the end of the file make that the last expression in the “body” of the `include`, and thus causes `include` to return `nothing`, and nothing to be printed in the REPL.

---

<div class="post-metadata">

**Author:** ![world-peace](https://avatars.discourse-cdn.com/v4/letter/w/9f8e36/32.png) [@world-peace](https://discourse.julialang.org/u/world-peace)\
**Post date:** [November 8, 2024, 9:05am UTC](https://discourse.julialang.org/t/strange-text-output-from-running-julia-tests/122379/8 "2024-11-08T09:05:02Z")

</div>

> [@goerz](#):
>
> This really goes back to your earlier confusion

I don’t particularly appreciate this comment.

I am not, as you put it “confused”. I objected to this particular Julia function behaving in an unusual way, a way which is different to _ **all other functions** _ in _ **any other programming language** _ which I know of.

As it happens, I was persuaded by the discussion. Now my opinion is somewhat different.

---

<div class="post-metadata">

**Author:** ![goerz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/goerz/32/3269_2.png) [@goerz](https://discourse.julialang.org/u/goerz)\
**Post date:** [November 8, 2024, 12:49pm UTC](https://discourse.julialang.org/t/strange-text-output-from-running-julia-tests/122379/9 "2024-11-08T12:49:26Z")

</div>

I should have said “question”, not “confusion”. This was not meant as an insult. Julia has many design decisions that lead to things working differently from other languages, in subtle ways. For someone relatively new to the language, it is more than natural to have their assumptions challenged. It takes months (at least) to understand the nuances of some of Julia’s concepts. For example, it took me some time to really understand _why_ if I define a function `f(a)` I can’t call with `f(a=1)`, the way I can in Python and Fortran. That is, the full consequences of multiple dispatch as a central paradigm of the language. And, some (smaller) design decisions might be arbitrary, and might even be something that I disagree with (`if substr in str` comes to mind).

In this case, it seemed that there was a design decision in Julia about expressions and their return values that you hadn’t fully wrapped your head around yet. Again, nothing wrong with that! I just wanted to point out the connection between the two questions, as they both derived from not fully being familiar yet with the same principle of Julia’s design.

---

<div class="post-metadata">

**Author:** ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)\
**Post date:** [November 8, 2024, 1:02pm UTC](https://discourse.julialang.org/t/strange-text-output-from-running-julia-tests/122379/10 "2024-11-08T13:02:52Z")

</div>

I usually put

```julia
nothing

```

as last line of a test script to avoid strange output.
