meshpro/dmsh

generate(geo, show=True) cycles through many plots in tests

drew-parsons opened this issue · 13 comments

Several of the dmsh 0.1.5 tests display a plot of the mesh when show=True is provided to dmsh.generate. Some of them cycle repeatedly display the mesh many many times. The worst offender is test_union_rectangles.py, but test_square_hole.py also displays many times before stopping*.

I presume there is some iteration taking place for the generation of these test meshes, and some matplotlib code is set to show the plot at each iteration.

  • edit: also test_circle.py, when running pytest-3 rather than python3 test_circle.py

Use

MPLBACKEND=Agg pytest

The figures aren't displayed then.

Yes, deactivating the plots altogether is easy enough (your environment variable is a better idea than my idea of patching in show=False).

But when you are displaying them, you don't want test_union_rectangles.py to display an endless series of the plots, do you?

Well, I want the show=True functionality to work and I want to have it covered by tests.

Well yes. But do you mean your intention is to show every single iteration? test_union_rectangles.py never stops in that case, never returns, so you can't say the test passed.

test_union_rectangles.py never stops in that case

I don't understand. The show=True functionality should not affect the convergence at all.

show shouldn't be blocking with MPLBACKEND=Agg pytest.

It's the issue that I'm reporting here. It shows an endless stream of plots. You have to press q to close each one individually. Is there actually a finite number of them? I got tired of pressing q so I just killed the test. Here I mean without the MPLBACKEND setting.
It returns eventually when I use MPLBACKEND=Agg. So that's a practical workaround. Not entirely intuitive though.

Not entirely intuitive though.

I should probably add it to the readme, yes. Using MPLBACKEND=Agg is what I do on all of my projects that have plotting. I don't know of a better way.

So that's a practical workaround.

It's actually meant to be used that way.

It's actually meant to be used that way.

Heh documenting in the test dir (or readme) should help then.

Perhaps I should set the environment variable in the tests.

Perhaps, though it can be nice to see the plots when you run tests manually. Could perhaps set the env variable for the troublemaking tests. But maybe it cleaner to apply it to them all.

Alright, I've added some instructions to the readme, that'll do for now.

Thanks Nico.