How to run unittests at build time?
Hello, at (Debian) package build time, it would be really important to run the tests suite, but I'm not getting how to do that. The simple approach doesn't work:
$ PYTHONPATH=build/lib.linux-x86_64-2.6 python -c "import numpy; numpy.test()" Traceback (most recent call last): File "<string>", line 1, in <module> File "numpy/__init__.py", line 127, in <module> raise ImportError(msg) ImportError: Error importing numpy: you should not try to import numpy from its source directory; please exit the numpy source tree, and relaunch your python intepreter from there. <<<
because '.' is placed first in the sys.path list, so it gets used the numpy/ dir in . instead the one in build/lib... . Ok, so let's tune sys.path:
$ python -c "import sys ; sys.path.insert(0, 'build/lib.linux-x86_64-2.6') ; import numpy; numpy.test()" Running unit tests for numpy NumPy version 1.6.1 NumPy is installed in build/lib.linux-x86_64-2.6/numpy Python version 2.6.7 (r267:88850, Aug 3 2011, 11:33:52) [GCC 4.6.1] nose version 1.0.0 EEEEEEE ====================================================================== ERROR: Failure: NameError (name 'numeric' is not defined)
Traceback (most recent call last): File "/usr/lib/pymodules/python2.6/nose/loader.py", line 390, in loadTestsFromName addr.filename, addr.module) File "/usr/lib/pymodules/python2.6/nose/importer.py", line 39, in importFromPath return self.importFromDir(dir_path, fqname) File "/usr/lib/pymodules/python2.6/nose/importer.py", line 84, in importFromDir mod = load_module(part_fqname, fh, filename, desc) File "build/lib.linux-x86_64-2.6/numpy/core/__init__.py", line 30, in <module> __all__ += numeric.__all__ NameError: name 'numeric' is not defined ====================================================================== ERROR: Failure: ImportError (cannot import name log) ---------------------------------------------------------------------- Traceback (most recent call last): File "/usr/lib/pymodules/python2.6/nose/loader.py", line 390, in loadTestsFromName addr.filename, addr.module) File "/usr/lib/pymodules/python2.6/nose/importer.py", line 39, in importFromPath return self.importFromDir(dir_path, fqname) File "/usr/lib/pymodules/python2.6/nose/importer.py", line 86, in importFromDir mod = load_module(part_fqname, fh, filename, desc) File "build/lib.linux-x86_64-2.6/numpy/distutils/fcompiler/__init__.py", line 37, in <module> from numpy.distutils import log ImportError: cannot import name log ====================================================================== ERROR: Failure: NameError (name 'type_check' is not defined) ---------------------------------------------------------------------- Traceback (most recent call last): File "/usr/lib/pymodules/python2.6/nose/loader.py", line 390, in loadTestsFromName addr.filename, addr.module) File "/usr/lib/pymodules/python2.6/nose/importer.py", line 39, in importFromPath return self.importFromDir(dir_path, fqname) File "/usr/lib/pymodules/python2.6/nose/importer.py", line 84, in importFromDir mod = load_module(part_fqname, fh, filename, desc) File "build/lib.linux-x86_64-2.6/numpy/lib/__init__.py", line 23, in <module> __all__ += type_check.__all__ NameError: name 'type_check' is not defined ====================================================================== ERROR: Failure: NameError (name 'numeric' is not defined) ---------------------------------------------------------------------- Traceback (most recent call last): File "/usr/lib/pymodules/python2.6/nose/loader.py", line 390, in loadTestsFromName addr.filename, addr.module) File "/usr/lib/pymodules/python2.6/nose/importer.py", line 39, in importFromPath return self.importFromDir(dir_path, fqname) File "/usr/lib/pymodules/python2.6/nose/importer.py", line 86, in importFromDir mod = load_module(part_fqname, fh, filename, desc) File "build/lib.linux-x86_64-2.6/numpy/ma/testutils.py", line 17, in <module> import numpy.core.umath as umath File "build/lib.linux-x86_64-2.6/numpy/core/__init__.py", line 30, in <module> __all__ += numeric.__all__ NameError: name 'numeric' is not defined ====================================================================== ERROR: Failure: NameError (name 'defmatrix' is not defined) ---------------------------------------------------------------------- Traceback (most recent call last): File "/usr/lib/pymodules/python2.6/nose/loader.py", line 390, in loadTestsFromName addr.filename, addr.module) File "/usr/lib/pymodules/python2.6/nose/importer.py", line 39, in importFromPath return self.importFromDir(dir_path, fqname) File "/usr/lib/pymodules/python2.6/nose/importer.py", line 84, in importFromDir mod = load_module(part_fqname, fh, filename, desc) File "build/lib.linux-x86_64-2.6/numpy/matrixlib/__init__.py", line 4, in <module> __all__ = defmatrix.__all__ NameError: name 'defmatrix' is not defined ====================================================================== ERROR: Failure: NameError (name 'numeric' is not defined) ---------------------------------------------------------------------- Traceback (most recent call last): File "/usr/lib/pymodules/python2.6/nose/loader.py", line 390, in loadTestsFromName addr.filename, addr.module) File "/usr/lib/pymodules/python2.6/nose/importer.py", line 39, in importFromPath return self.importFromDir(dir_path, fqname) File "/usr/lib/pymodules/python2.6/nose/importer.py", line 86, in importFromDir mod = load_module(part_fqname, fh, filename, desc) File "build/lib.linux-x86_64-2.6/numpy/oldnumeric/__init__.py", line 14, in <module> from compat import * File "build/lib.linux-x86_64-2.6/numpy/oldnumeric/compat.py", line 13, in <module> import numpy.core.multiarray as multiarray File "build/lib.linux-x86_64-2.6/numpy/core/__init__.py", line 30, in <module> __all__ += numeric.__all__ NameError: name 'numeric' is not defined ====================================================================== ERROR: Failure: NameError (name 'type_check' is not defined) ---------------------------------------------------------------------- Traceback (most recent call last): File "/usr/lib/pymodules/python2.6/nose/loader.py", line 390, in loadTestsFromName addr.filename, addr.module) File "/usr/lib/pymodules/python2.6/nose/importer.py", line 39, in importFromPath return self.importFromDir(dir_path, fqname) File "/usr/lib/pymodules/python2.6/nose/importer.py", line 84, in importFromDir mod = load_module(part_fqname, fh, filename, desc) File "build/lib.linux-x86_64-2.6/numpy/polynomial/__init__.py", line 28, in <module> from numpy.lib import deprecate File "build/lib.linux-x86_64-2.6/numpy/lib/__init__.py", line 23, in <module> __all__ += type_check.__all__ NameError: name 'type_check' is not defined ---------------------------------------------------------------------- Ran 7 tests in 0.004s FAILED (errors=7) <<< Not nice either, let's try another way, importing * from numpy: $ python -c "import sys ; sys.path.insert(0, 'build/lib.linux-x86_64-2.6') ; import numpy; from numpy import * ; numpy.test()" same result as above. So, what's the proper way to run the tests suite at build time? Thanks in advance, -- Sandro Tosi (aka morph, morpheus, matrixhasu) My website: http://matrixhasu.altervista.org/ Me at Debian: http://wiki.debian.org/SandroTosi
On Wed, Sep 21, 2011 at 15:56, Sandro Tosi <morph@debian.org> wrote:
Hello, at (Debian) package build time, it would be really important to run the tests suite, but I'm not getting how to do that.
The way that nosetests imports packages in order to navigate to find test files is a bit wonky. It doesn't respect proper package semantics. Or perhaps just the behavior that we see from normal imports. In particular, many of our __init__.py files do something like this: from foo import ** __all__ = [] __all__.extend(foo.__all__) The reason why this normally works is that once you do any kind of import from the foo submodule, it gets added to the namespace of the package's actual module object. However, nosetests is manually "importing" the __init__.py file and bypassing the normal import mechanism, so it misses some of these semantics. I suspect nosetests may be doing something different to load files that have been installed into site-packages rather than other locations. Unfortunately, I don't know a workaround other than to modify all of our __init__.py file to do more explicit imports rather than relying on the implicit behavior of the full Python import mechanism. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco
Don't know about about Debian, but this works OK for RPM distros: PYTHONPATH="%{buildroot}%{py_sitedir}" %{__python} -c \ "import pkg_resources, numpy ; numpy.test()" The only thing you are missing is the "import pkg_resources", let me know if that works for you. -Filipe On Wed, Sep 21, 2011 at 16:56, Sandro Tosi <morph@debian.org> wrote:
Hello, at (Debian) package build time, it would be really important to run the tests suite, but I'm not getting how to do that.
The simple approach doesn't work:
$ PYTHONPATH=build/lib.linux-x86_64-2.6 python -c "import numpy; numpy.test()" Traceback (most recent call last): File "<string>", line 1, in <module> File "numpy/__init__.py", line 127, in <module> raise ImportError(msg) ImportError: Error importing numpy: you should not try to import numpy from its source directory; please exit the numpy source tree, and relaunch your python intepreter from there. <<<
because '.' is placed first in the sys.path list, so it gets used the numpy/ dir in . instead the one in build/lib... . Ok, so let's tune sys.path:
$ python -c "import sys ; sys.path.insert(0, 'build/lib.linux-x86_64-2.6') ; import numpy; numpy.test()" Running unit tests for numpy NumPy version 1.6.1 NumPy is installed in build/lib.linux-x86_64-2.6/numpy Python version 2.6.7 (r267:88850, Aug 3 2011, 11:33:52) [GCC 4.6.1] nose version 1.0.0 EEEEEEE ====================================================================== ERROR: Failure: NameError (name 'numeric' is not defined)
Traceback (most recent call last): File "/usr/lib/pymodules/python2.6/nose/loader.py", line 390, in loadTestsFromName addr.filename, addr.module) File "/usr/lib/pymodules/python2.6/nose/importer.py", line 39, in importFromPath return self.importFromDir(dir_path, fqname) File "/usr/lib/pymodules/python2.6/nose/importer.py", line 84, in importFromDir mod = load_module(part_fqname, fh, filename, desc) File "build/lib.linux-x86_64-2.6/numpy/core/__init__.py", line 30, in <module> __all__ += numeric.__all__ NameError: name 'numeric' is not defined
====================================================================== ERROR: Failure: ImportError (cannot import name log) ---------------------------------------------------------------------- Traceback (most recent call last): File "/usr/lib/pymodules/python2.6/nose/loader.py", line 390, in loadTestsFromName addr.filename, addr.module) File "/usr/lib/pymodules/python2.6/nose/importer.py", line 39, in importFromPath return self.importFromDir(dir_path, fqname) File "/usr/lib/pymodules/python2.6/nose/importer.py", line 86, in importFromDir mod = load_module(part_fqname, fh, filename, desc) File "build/lib.linux-x86_64-2.6/numpy/distutils/fcompiler/__init__.py", line 37, in <module> from numpy.distutils import log ImportError: cannot import name log
====================================================================== ERROR: Failure: NameError (name 'type_check' is not defined) ---------------------------------------------------------------------- Traceback (most recent call last): File "/usr/lib/pymodules/python2.6/nose/loader.py", line 390, in loadTestsFromName addr.filename, addr.module) File "/usr/lib/pymodules/python2.6/nose/importer.py", line 39, in importFromPath return self.importFromDir(dir_path, fqname) File "/usr/lib/pymodules/python2.6/nose/importer.py", line 84, in importFromDir mod = load_module(part_fqname, fh, filename, desc) File "build/lib.linux-x86_64-2.6/numpy/lib/__init__.py", line 23, in <module> __all__ += type_check.__all__ NameError: name 'type_check' is not defined
====================================================================== ERROR: Failure: NameError (name 'numeric' is not defined) ---------------------------------------------------------------------- Traceback (most recent call last): File "/usr/lib/pymodules/python2.6/nose/loader.py", line 390, in loadTestsFromName addr.filename, addr.module) File "/usr/lib/pymodules/python2.6/nose/importer.py", line 39, in importFromPath return self.importFromDir(dir_path, fqname) File "/usr/lib/pymodules/python2.6/nose/importer.py", line 86, in importFromDir mod = load_module(part_fqname, fh, filename, desc) File "build/lib.linux-x86_64-2.6/numpy/ma/testutils.py", line 17, in <module> import numpy.core.umath as umath File "build/lib.linux-x86_64-2.6/numpy/core/__init__.py", line 30, in <module> __all__ += numeric.__all__ NameError: name 'numeric' is not defined
====================================================================== ERROR: Failure: NameError (name 'defmatrix' is not defined) ---------------------------------------------------------------------- Traceback (most recent call last): File "/usr/lib/pymodules/python2.6/nose/loader.py", line 390, in loadTestsFromName addr.filename, addr.module) File "/usr/lib/pymodules/python2.6/nose/importer.py", line 39, in importFromPath return self.importFromDir(dir_path, fqname) File "/usr/lib/pymodules/python2.6/nose/importer.py", line 84, in importFromDir mod = load_module(part_fqname, fh, filename, desc) File "build/lib.linux-x86_64-2.6/numpy/matrixlib/__init__.py", line 4, in <module> __all__ = defmatrix.__all__ NameError: name 'defmatrix' is not defined
====================================================================== ERROR: Failure: NameError (name 'numeric' is not defined) ---------------------------------------------------------------------- Traceback (most recent call last): File "/usr/lib/pymodules/python2.6/nose/loader.py", line 390, in loadTestsFromName addr.filename, addr.module) File "/usr/lib/pymodules/python2.6/nose/importer.py", line 39, in importFromPath return self.importFromDir(dir_path, fqname) File "/usr/lib/pymodules/python2.6/nose/importer.py", line 86, in importFromDir mod = load_module(part_fqname, fh, filename, desc) File "build/lib.linux-x86_64-2.6/numpy/oldnumeric/__init__.py", line 14, in <module> from compat import * File "build/lib.linux-x86_64-2.6/numpy/oldnumeric/compat.py", line 13, in <module> import numpy.core.multiarray as multiarray File "build/lib.linux-x86_64-2.6/numpy/core/__init__.py", line 30, in <module> __all__ += numeric.__all__ NameError: name 'numeric' is not defined
====================================================================== ERROR: Failure: NameError (name 'type_check' is not defined) ---------------------------------------------------------------------- Traceback (most recent call last): File "/usr/lib/pymodules/python2.6/nose/loader.py", line 390, in loadTestsFromName addr.filename, addr.module) File "/usr/lib/pymodules/python2.6/nose/importer.py", line 39, in importFromPath return self.importFromDir(dir_path, fqname) File "/usr/lib/pymodules/python2.6/nose/importer.py", line 84, in importFromDir mod = load_module(part_fqname, fh, filename, desc) File "build/lib.linux-x86_64-2.6/numpy/polynomial/__init__.py", line 28, in <module> from numpy.lib import deprecate File "build/lib.linux-x86_64-2.6/numpy/lib/__init__.py", line 23, in <module> __all__ += type_check.__all__ NameError: name 'type_check' is not defined
---------------------------------------------------------------------- Ran 7 tests in 0.004s
FAILED (errors=7) <<<
Not nice either, let's try another way, importing * from numpy:
$ python -c "import sys ; sys.path.insert(0, 'build/lib.linux-x86_64-2.6') ; import numpy; from numpy import * ; numpy.test()"
same result as above.
So, what's the proper way to run the tests suite at build time?
Thanks in advance, -- Sandro Tosi (aka morph, morpheus, matrixhasu) My website: http://matrixhasu.altervista.org/ Me at Debian: http://wiki.debian.org/SandroTosi _______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
On Wed, Sep 21, 2011 at 16:15, Filipe Pires Alvarenga Fernandes <ocefpaf@gmail.com> wrote:
Don't know about about Debian, but this works OK for RPM distros:
PYTHONPATH="%{buildroot}%{py_sitedir}" %{__python} -c \ "import pkg_resources, numpy ; numpy.test()"
The only thing you are missing is the "import pkg_resources", let me know if that works for you.
What does py_sitedir expand to, usually? I don't think pkg_resources has anything to do with it. numpy doesn't use it, and I don't think nosetests does either (well, only for its plugin mechanism, but that's neither here nor there). In any case, I've tried importing pkg_resources while running from the build/lib.*/ directory and still get the same errors as reported by Sandro. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco
On Wed, Sep 21, 2011 at 23:20, Robert Kern <robert.kern@gmail.com> wrote:
On Wed, Sep 21, 2011 at 16:15, Filipe Pires Alvarenga Fernandes <ocefpaf@gmail.com> wrote:
Don't know about about Debian, but this works OK for RPM distros:
PYTHONPATH="%{buildroot}%{py_sitedir}" %{__python} -c \ "import pkg_resources, numpy ; numpy.test()"
The only thing you are missing is the "import pkg_resources", let me know if that works for you.
What does py_sitedir expand to, usually?
I suppose the site-packages directory location, so something like /usr/lib/python2.6/site-packages/
I don't think pkg_resources has anything to do with it. numpy doesn't use it, and I don't think nosetests does either (well, only for its plugin mechanism, but that's neither here nor there).
ack, I didn't use it in my tests: it works fine the python -c "import numpy; numpy.test()"
In any case, I've tried importing pkg_resources while running from the build/lib.*/ directory and still get the same errors as reported by Sandro.
Yep, the different with my approach and Felipe's one is I ran from the build directory Felipe from the installation directory. It works, so I'll use the latter Cheers, -- Sandro Tosi (aka morph, morpheus, matrixhasu) My website: http://matrixhasu.altervista.org/ Me at Debian: http://wiki.debian.org/SandroTosi
On Wed, Sep 21, 2011 at 17:29, Sandro Tosi <morph@debian.org> wrote:
On Wed, Sep 21, 2011 at 23:20, Robert Kern <robert.kern@gmail.com> wrote:
On Wed, Sep 21, 2011 at 16:15, Filipe Pires Alvarenga Fernandes <ocefpaf@gmail.com> wrote:
Don't know about about Debian, but this works OK for RPM distros:
PYTHONPATH="%{buildroot}%{py_sitedir}" %{__python} -c \ "import pkg_resources, numpy ; numpy.test()"
The only thing you are missing is the "import pkg_resources", let me know if that works for you.
What does py_sitedir expand to, usually?
I suppose the site-packages directory location, so something like /usr/lib/python2.6/site-packages/
Yep. That's correct. If you want to look at the whole spec file: https://build.opensuse.org/package/view_file?file=python-numpy.spec&package=python-numpy&project=home%3Aocefpaf&srcmd5=ffa9c6e1b9a6f715f0101eb334c5b5a8
I don't think pkg_resources has anything to do with it. numpy doesn't use it, and I don't think nosetests does either (well, only for its plugin mechanism, but that's neither here nor there).
ack, I didn't use it in my tests: it works fine the python -c "import numpy; numpy.test()"
In any case, I've tried importing pkg_resources while running from the build/lib.*/ directory and still get the same errors as reported by Sandro.
You are right, I just removed pkg_resources and things still work OK.
Yep, the different with my approach and Felipe's one is I ran from the build directory Felipe from the installation directory. It works, so I'll use the latter
Cheers, -- Sandro Tosi (aka morph, morpheus, matrixhasu) My website: http://matrixhasu.altervista.org/ Me at Debian: http://wiki.debian.org/SandroTosi _______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
On Wed, Sep 21, 2011 at 23:15, Filipe Pires Alvarenga Fernandes <ocefpaf@gmail.com> wrote:
Don't know about about Debian, but this works OK for RPM distros:
PYTHONPATH="%{buildroot}%{py_sitedir}" %{__python} -c \ "import pkg_resources, numpy ; numpy.test()"
The only thing you are missing is the "import pkg_resources", let me know if that works for you.
Ok it works: I have to run tests from the installed location and not from the build/ subdir; Thanks!! Cheers, -- Sandro Tosi (aka morph, morpheus, matrixhasu) My website: http://matrixhasu.altervista.org/ Me at Debian: http://wiki.debian.org/SandroTosi
participants (3)
-
Filipe Pires Alvarenga Fernandes
-
Robert Kern
-
Sandro Tosi