# Testing a package with runtests.jl does not generate graphical outputs

**URL:** <https://discourse.julialang.org/t/testing-a-package-with-runtests-jl-does-not-generate-graphical-outputs/16539>\
**Category:** Internals & Design\
**Tags:** package, plotting\
**Created:** [October 19, 2018, 6:04pm UTC](https://discourse.julialang.org/t/testing-a-package-with-runtests-jl-does-not-generate-graphical-outputs/16539 "2018-10-19T18:04:18Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![BVPs](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bvps/32/2190_2.png) [@BVPs](https://discourse.julialang.org/u/BVPs)\
**Post date:** [October 19, 2018, 6:04pm UTC](https://discourse.julialang.org/t/testing-a-package-with-runtests-jl-does-not-generate-graphical-outputs/16539/1 "2018-10-19T18:04:18Z")

</div>

My students and I have been developing a package in Julia, and under the `test` directory, we have a file `runtests.jl` as the other packages. In it, we try to run some plotting functions to show some graphics (via `Plots.jl`), but when I run this via `] test MyPackage`, say, the test passes without any errors, but it does not generate any graphical plots. Is this an intended design for testing packages via `runtests.jl`? In fact, when I tried the standard graphics packages, e.g., `] test GR`, `] test Plots`, etc., the tests passed without any errors, but no graphical outputs were generated either.

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [October 20, 2018, 6:24am UTC](https://discourse.julialang.org/t/testing-a-package-with-runtests-jl-does-not-generate-graphical-outputs/16539/2 "2018-10-20T06:24:03Z")

</div>

> [@BVPs](#):
>
> we try to run some plotting functions to show some graphics (via `Plots.jl` ), but when I run this via `] test MyPackage` , say, the test passes without any errors, but it does not generate any graphical plots.

Hard to say more without a minimal working example.

> [@Please read: make it easier to help you](https://discourse.julialang.org/t/psa-make-it-easier-to-help-you/14757):
>
> Welcome to the Julia Discourse! We are enthusiastic about helping Julia programmers, both beginner and experienced. This public service announcement (PSA) outlines best practices when asking for help. Following these points makes it easier for us to help you and more likely you’ll get a prompt, useful answer. Keywords are highlighted to make it easier to refer to specific points. Choose a descriptive title that captures the key part of your question, eg “plots with multiple axes” instead of …

---

<div class="post-metadata">

**Author:** ![tim.holy](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tim.holy/32/52_2.png) [@tim.holy](https://discourse.julialang.org/u/tim.holy)\
**Post date:** [October 20, 2018, 10:05am UTC](https://discourse.julialang.org/t/testing-a-package-with-runtests-jl-does-not-generate-graphical-outputs/16539/3 "2018-10-20T10:05:10Z")

</div>

Try capturing the output and then calling `display`:

```julia
julia> p = plot(rand(5)); # no graphical output produced

julia> typeof(p)
Plots.Plot{Plots.GRBackend}

julia> display(p)

```

When you don’t use the semicolon, the `show`/`display` method is called implicitly, which is why you expect to see graphical output.

If you’re running your code with `julia plottingscript.jl`, the other potential cause would be the script finishing before the window appears. Tricks such as described [here](http://juliagraphics.github.io/Gtk.jl/latest/manual/nonreplusage.html) may be useful, though the `signal_connect` would have to be replaced by whatever needed to monitor for window closure.

---

<div class="post-metadata">

**Author:** ![yqshao](https://avatars.discourse-cdn.com/v4/letter/y/e8c25b/32.png) [@yqshao](https://discourse.julialang.org/u/yqshao)\
**Post date:** [October 21, 2018, 1:02am UTC](https://discourse.julialang.org/t/testing-a-package-with-runtests-jl-does-not-generate-graphical-outputs/16539/4 "2018-10-21T01:02:55Z")

</div>

Hi, Tim.  
Thanks for your advice. I have tried both methods you mentioned. However, the image still can’t be displayed. The best I can get is one line of "Plot{Plots.GRBackend() n=1} " showing that one image variable was created.

---

<div class="post-metadata">

**Author:** ![Nikos\_Gianniotis](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nikos_gianniotis/32/11487_2.png) [@Nikos\_Gianniotis](https://discourse.julialang.org/u/Nikos_Gianniotis)\
**Post date:** [December 7, 2021, 11:30am UTC](https://discourse.julialang.org/t/testing-a-package-with-runtests-jl-does-not-generate-graphical-outputs/16539/5 "2021-12-07T11:30:36Z")

</div>

Probably far too late, but I recently encountered the same problem when using the package PyPlot.jl when executing the tests in `tests\runtests.jl` of my project.

What worked for me was to call `ion()` before the first plot command.  
After creating the plot, I used `pause(5)` to allow some time for inspecting the plot.  
After that, I closed the plot and finally issued `ioff()`.

---

<div class="post-metadata">

**Author:** ![BVPs](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bvps/32/2190_2.png) [@BVPs](https://discourse.julialang.org/u/BVPs)\
**Post date:** [December 7, 2021, 4:59pm UTC](https://discourse.julialang.org/t/testing-a-package-with-runtests-jl-does-not-generate-graphical-outputs/16539/6 "2021-12-07T16:59:13Z")

</div>

@Nikos_Gianniotis ; thanks a lot for your suggestion. But have you tried these `ion` and `ioff` under `Plots.jl`’s `pyplot()` backend? I am not using `PyPlot.jl` directly. I always use `Plots.jl` with various backends.

---

<div class="post-metadata">

**Author:** ![Nikos\_Gianniotis](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nikos_gianniotis/32/11487_2.png) [@Nikos\_Gianniotis](https://discourse.julialang.org/u/Nikos_Gianniotis)\
**Post date:** [December 7, 2021, 9:45pm UTC](https://discourse.julialang.org/t/testing-a-package-with-runtests-jl-does-not-generate-graphical-outputs/16539/7 "2021-12-07T21:45:41Z")

</div>

Hi @BVPs. I’m afraid I only ever use PyPlot.jl and have no experience with other plotting packages. I understand that Plot.jl can use PyPlot.jl as a backend, but I have never even installed it. One hears good things about Plots.jl though…sorry!

---

<div class="post-metadata">

**Author:** ![gustaphe](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gustaphe/32/18174_2.png) [@gustaphe](https://discourse.julialang.org/u/gustaphe)\
**Post date:** [December 8, 2021, 5:40am UTC](https://discourse.julialang.org/t/testing-a-package-with-runtests-jl-does-not-generate-graphical-outputs/16539/8 "2021-12-08T05:40:53Z")

</div>

In this situation I would probably have it save the images as png or pdf.
