testing issue involving matplotlib

Helllo, I’m seeing a strange issue when running unittests on python3.3 and python3.4 that somehow involves matplotlib. My code has a somewhat complicated setup, but I think I’ve boiled the issue down to the following reproduction steps

import unittest

import warnings

import matplotlib.pyplot

class TestMe(unittest.TestCase):

def test_warn(self):

    with self.assertWarns(UserWarning):

        warnings.warn("a warning", UserWarning)

if name == “main”:

unittest.main()

It looks like it should pass, but it errors as follows

E

···

======================================================================

ERROR: test_warn (main.TestMe)


Traceback (most recent call last):

File “/homes/5/jevans/Downloads/testit.py”, line 8, in test_warn

with self.assertWarns(UserWarning):

File “/space/getafix/1/users/jevans/anaconda/envs/py3k/lib/python3.3/unittest/case.py”, line 177, in enter

for v in sys.modules.values():

RuntimeError: dictionary changed size during iteration


Ran 1 test in 0.002

If the matplotlib import is changed to just

import matlotlib

or if the matplotlib import is commented out altogether, it then passes. I’m seeing the behavior on Anaconda with python 3.3 and matplotlib 1.3.1 on both mac and linux, but also with MacPorts with pythons 3.3 and 3.4, matplotlib 1.3.1. All seems fine with a Fedora 20 laptop with python 3.3 and also matplotlib 1.3.1.


John Evans

Hmmm, it isn’t the same, but I wonder if it is related to the oddities around https://github.com/matplotlib/matplotlib/pull/2925 . What I mean is that in that case, none of our unit tests caught the problem, even though it should have. In your case, your unit tests is catching a similar problem, but there is no obvious reason why there should be a problem.

Now, technically speaking, in your case, there is a bug in the unittest package (values() is an iterator in py3k rather than a list), but I wouldn’t know why that dictionary would change in the first place.

···

On Mon, Apr 14, 2014 at 2:54 PM, John Evans <john.g.evans.ne@…1896…> wrote:

Helllo, I’m seeing a strange issue when running unittests on python3.3 and python3.4 that somehow involves matplotlib. My code has a somewhat complicated setup, but I think I’ve boiled the issue down to the following reproduction steps

import unittest

import warnings

import matplotlib.pyplot

class TestMe(unittest.TestCase):

def test_warn(self):
    with self.assertWarns(UserWarning):
        warnings.warn("a warning", UserWarning)

if name == “main”:

unittest.main()

It looks like it should pass, but it errors as follows

E

======================================================================

ERROR: test_warn (main.TestMe)


Traceback (most recent call last):

File “/homes/5/jevans/Downloads/testit.py”, line 8, in test_warn

with self.assertWarns(UserWarning):

File “/space/getafix/1/users/jevans/anaconda/envs/py3k/lib/python3.3/unittest/case.py”, line 177, in enter

for v in sys.modules.values():

RuntimeError: dictionary changed size during iteration


Ran 1 test in 0.002

If the matplotlib import is changed to just

import matlotlib

or if the matplotlib import is commented out altogether, it then passes. I’m seeing the behavior on Anaconda with python 3.3 and matplotlib 1.3.1 on both mac and linux, but also with MacPorts with pythons 3.3 and 3.4, matplotlib 1.3.1. All seems fine with a Fedora 20 laptop with python 3.3 and also matplotlib 1.3.1.


John Evans


Learn Graph Databases - Download FREE O’Reilly Book

“Graph Databases” is the definitive new guide to graph databases and their

applications. Written by three acclaimed leaders in the field,

this first edition is now available. Download your free book today!

http://p.sf.net/sfu/NeoTech


Matplotlib-users mailing list

Matplotlib-users@lists.sourceforge.net

https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Just to close the loop on this, I figured out that the issue was minimally reproduced if the “import matplotlib.pyplot” line was replaced with just “import six”. It was reported to the six package developers and the problem was resolved with the 1.7.0 release of six.

···

On Wed, Apr 16, 2014 at 12:37 PM, Benjamin Root <ben.root@…1304…> wrote:

Hmmm, it isn’t the same, but I wonder if it is related to the oddities around https://github.com/matplotlib/matplotlib/pull/2925 . What I mean is that in that case, none of our unit tests caught the problem, even though it should have. In your case, your unit tests is catching a similar problem, but there is no obvious reason why there should be a problem.

Now, technically speaking, in your case, there is a bug in the unittest package (values() is an iterator in py3k rather than a list), but I wouldn’t know why that dictionary would change in the first place.


John Evans

On Mon, Apr 14, 2014 at 2:54 PM, John Evans <john.g.evans.ne@…287…> wrote:

Helllo, I’m seeing a strange issue when running unittests on python3.3 and python3.4 that somehow involves matplotlib. My code has a somewhat complicated setup, but I think I’ve boiled the issue down to the following reproduction steps

import unittest

import warnings

import matplotlib.pyplot

class TestMe(unittest.TestCase):

def test_warn(self):
    with self.assertWarns(UserWarning):
        warnings.warn("a warning", UserWarning)

if name == “main”:

unittest.main()

It looks like it should pass, but it errors as follows

E

======================================================================

ERROR: test_warn (main.TestMe)


Traceback (most recent call last):

File “/homes/5/jevans/Downloads/testit.py”, line 8, in test_warn

with self.assertWarns(UserWarning):

File “/space/getafix/1/users/jevans/anaconda/envs/py3k/lib/python3.3/unittest/case.py”, line 177, in enter

for v in sys.modules.values():

RuntimeError: dictionary changed size during iteration


Ran 1 test in 0.002

If the matplotlib import is changed to just

import matlotlib

or if the matplotlib import is commented out altogether, it then passes. I’m seeing the behavior on Anaconda with python 3.3 and matplotlib 1.3.1 on both mac and linux, but also with MacPorts with pythons 3.3 and 3.4, matplotlib 1.3.1. All seems fine with a Fedora 20 laptop with python 3.3 and also matplotlib 1.3.1.


John Evans


Learn Graph Databases - Download FREE O’Reilly Book

“Graph Databases” is the definitive new guide to graph databases and their

applications. Written by three acclaimed leaders in the field,

this first edition is now available. Download your free book today!

http://p.sf.net/sfu/NeoTech


Matplotlib-users mailing list

Matplotlib-users@lists.sourceforge.net

https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Thanks for the update.

···

On Tue, Jun 10, 2014 at 6:46 AM, John Evans <john.g.evans.ne@…287…> wrote:

Just to close the loop on this, I figured out that the issue was minimally reproduced if the “import matplotlib.pyplot” line was replaced with just “import six”. It was reported to the six package developers and the problem was resolved with the 1.7.0 release of six.

On Wed, Apr 16, 2014 at 12:37 PM, Benjamin Root <ben.root@…1836…304…> wrote:

Hmmm, it isn’t the same, but I wonder if it is related to the oddities around https://github.com/matplotlib/matplotlib/pull/2925 . What I mean is that in that case, none of our unit tests caught the problem, even though it should have. In your case, your unit tests is catching a similar problem, but there is no obvious reason why there should be a problem.

Now, technically speaking, in your case, there is a bug in the unittest package (values() is an iterator in py3k rather than a list), but I wouldn’t know why that dictionary would change in the first place.


John Evans

On Mon, Apr 14, 2014 at 2:54 PM, John Evans <john.g.evans.ne@…287…> wrote:

Helllo, I’m seeing a strange issue when running unittests on python3.3 and python3.4 that somehow involves matplotlib. My code has a somewhat complicated setup, but I think I’ve boiled the issue down to the following reproduction steps

import unittest

import warnings

import matplotlib.pyplot

class TestMe(unittest.TestCase):

def test_warn(self):
    with self.assertWarns(UserWarning):
        warnings.warn("a warning", UserWarning)

if name == “main”:

unittest.main()

It looks like it should pass, but it errors as follows

E

======================================================================

ERROR: test_warn (main.TestMe)


Traceback (most recent call last):

File “/homes/5/jevans/Downloads/testit.py”, line 8, in test_warn

with self.assertWarns(UserWarning):

File “/space/getafix/1/users/jevans/anaconda/envs/py3k/lib/python3.3/unittest/case.py”, line 177, in enter

for v in sys.modules.values():

RuntimeError: dictionary changed size during iteration


Ran 1 test in 0.002

If the matplotlib import is changed to just

import matlotlib

or if the matplotlib import is commented out altogether, it then passes. I’m seeing the behavior on Anaconda with python 3.3 and matplotlib 1.3.1 on both mac and linux, but also with MacPorts with pythons 3.3 and 3.4, matplotlib 1.3.1. All seems fine with a Fedora 20 laptop with python 3.3 and also matplotlib 1.3.1.


John Evans


Learn Graph Databases - Download FREE O’Reilly Book

“Graph Databases” is the definitive new guide to graph databases and their

applications. Written by three acclaimed leaders in the field,

this first edition is now available. Download your free book today!

http://p.sf.net/sfu/NeoTech


Matplotlib-users mailing list

Matplotlib-users@lists.sourceforge.net

https://lists.sourceforge.net/lists/listinfo/matplotlib-users