micropython-lib icon indicating copy to clipboard operation
micropython-lib copied to clipboard

unittest.main fails to discover tests

Open OpenBagTwo opened this issue 4 years ago • 3 comments

Running:

>>> import unittest
>>> unittest.main('my_package.tests.test_module')

results in

Ran 0 tests

OK

The workaround is to install test.support and utilize run_unittest but wow that's a lot of overhead.

The fix also appears to be to use the four-argument version of __import__:

Replace: https://github.com/micropython/micropython-lib/blob/eae01bd4e4cd1b22d9ccfedbd6bf9d879f64d9bd/unittest/unittest.py#L217

with:

    m = __import__(module, None, ['object'], True)

Issue present with:

  • MicroPython
    • v1.14 on 2021-02-02; ESP module with ESP8266
    • 3d45bca-dirty on 2021-02-02; linux version
  • micropython-unittest
    • 0.3.2

OpenBagTwo avatar Feb 17 '21 00:02 OpenBagTwo

Ah. Just discovered that this version of __import__ causes MemoryErrors on an ESP82xx boards (encountered using MicroPython v1.14 on 2021-02-02; ESP module (1M) with ESP8266). I'll go ahead and close this and figure out a better way to do unit test discovery.

OpenBagTwo avatar Apr 11 '21 14:04 OpenBagTwo

Never mind. The issue was actually that my unit tests themselves exhausted the microcontroller's memory--I can't even directly import the test module. So the four-arg version of __import__ itself is not the problem.

OpenBagTwo avatar Apr 11 '21 14:04 OpenBagTwo

There has been some significant improvements in the unittest library recently - including around discovery. See #488 for details. Could you please update to the latest unittest library and try again?

mattytrentini avatar Jul 03 '22 14:07 mattytrentini

This should be fixed now that #488 is merged.

dpgeorge avatar Oct 04 '22 01:10 dpgeorge