Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Replace nose with pytest. #19

Merged
merged 1 commit into from Sep 26, 2020
Merged

WIP: Replace nose with pytest. #19

merged 1 commit into from Sep 26, 2020

Conversation

mcepl
Copy link
Contributor

@mcepl mcepl commented Aug 7, 2020

I am a maintainer of Python packages in openSUSE, and I am on my crusade of eliminating nose1 from our distribution. When I look at its repository on https://github.com/nose-devs/nose, the last release 1.3.7 was on 2 Jun 2015, and even the last commit on the master branch was on 4 Mar 2016. Also, nose won't be supported starting with Python 3.9/3.10.

This pull request should eliminate dependency on nose. Resulting test suite depends on pytest, which is currently perfectly developed and maintained.

Unfortunately, I wasn’t able to debug it properly, somehow this package is too complicated for me. When running in plain working repository just with pytest -v I get:

lml@stitny (remove_nose)$ pytest -v
Test session starts (platform: linux, Python 3.8.4, pytest 4.6.9, pytest-sugar 0.9.3)
cachedir: .pytest_cache
rootdir: /home/matej/archiv/knihovna/repos/lml
plugins: expect-1.1.0, sugar-0.9.3, xdist-1.32.0, mock-3.1.1, cov-2.10.0, forked-1.2.0
collecting ... 
――――――――――――――――――――――――――――――――――――――――――――――――――――――――― ERROR collecting examples/robotchef_allinone/tests/test_robot_chef.py ――――――――――――――――――――――――――――――――――――――――――――――――――――――――――
import file mismatch:
imported module 'test_robot_chef' has this __file__ attribute:
  /home/matej/archiv/knihovna/repos/lml/examples/robotchef/tests/test_robot_chef.py
which is not the same as the test file we want to collect:
  /home/matej/archiv/knihovna/repos/lml/examples/robotchef_allinone/tests/test_robot_chef.py
HINT: remove __pycache__ / .pyc files and/or use a unique basename for your test file modules

――――――――――――――――――――――――――――――――――――――――――――――――――――――― ERROR collecting examples/robotchef_allinone_lml/tests/test_robot_chef.py ――――――――――――――――――――――――――――――――――――――――――――――――――――――――
import file mismatch:
imported module 'test_robot_chef' has this __file__ attribute:
  /home/matej/archiv/knihovna/repos/lml/examples/robotchef/tests/test_robot_chef.py
which is not the same as the test file we want to collect:
  /home/matej/archiv/knihovna/repos/lml/examples/robotchef_allinone_lml/tests/test_robot_chef.py
HINT: remove __pycache__ / .pyc files and/or use a unique basename for your test file modules

――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― ERROR collecting examples/v2/robotchef_v2/tests/test_robot_chef.py ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――
import file mismatch:
imported module 'test_robot_chef' has this __file__ attribute:
  /home/matej/archiv/knihovna/repos/lml/examples/robotchef/tests/test_robot_chef.py
which is not the same as the test file we want to collect:
  /home/matej/archiv/knihovna/repos/lml/examples/v2/robotchef_v2/tests/test_robot_chef.py
HINT: remove __pycache__ / .pyc files and/or use a unique basename for your test file modules

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Interrupted: 3 errors during collection !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

Results (0.26s):
lml@stitny (remove_nose)$

(yes, I made sure that all *.pyc files have been removed prior to running this)

Inside our building system, the situation is not much better:

[    3s] + PYTHONPATH=/home/abuild/rpmbuild/BUILDROOT/python-lml-0.0.9-0.x86_64/usr/lib/python3.8/site-packages
[    3s] + PYTHONDONTWRITEBYTECODE=1
[    3s] + pytest-3.8 --ignore=_build.python2 --ignore=_build.python3 --ignore=_build.pypy3 -v README.rst tests/test_plugin_info.py tests/test_plugin_loader.py tests/test_plugin_manager.py tests/test_utils.py
[    3s] ============================= test session starts ==============================
[    3s] platform linux -- Python 3.8.4, pytest-5.4.3, py-1.9.0, pluggy-0.13.1 -- /usr/bin/python3
[    3s] cachedir: .pytest_cache
[    3s] rootdir: /home/abuild/rpmbuild/BUILD/lml-0.0.9
[    3s] collecting ... collected 31 items
[    3s] 
[    3s] tests/test_plugin_info.py::test_plugin_info PASSED                       [  3%]
[    3s] tests/test_plugin_info.py::test_module_name_scenario_2 PASSED            [  6%]
[    3s] tests/test_plugin_loader.py::test_load_from_pyinstaller PASSED           [  9%]
[    3s] tests/test_plugin_loader.py::test_load_from_pyinstaller_with_regex PASSED [ 12%]
[    3s] tests/test_plugin_loader.py::test_load_plugins FAILED                    [ 16%]
[    4s] tests/test_plugin_loader.py::test_load_plugins_without_pyinstaller FAILED [ 19%]
[    4s] tests/test_plugin_loader.py::test_load_plugins_without_any_plugins PASSED [ 22%]
[    4s] tests/test_plugin_loader.py::test_load_plugins_without_black_list PASSED [ 25%]
[    4s] tests/test_plugin_loader.py::test_load_plugins_import_error PASSED       [ 29%]
[    4s] tests/test_plugin_manager.py::test_plugin_manager PASSED                 [ 32%]
[    4s] tests/test_plugin_manager.py::test_load_me_later PASSED                  [ 35%]
[    4s] tests/test_plugin_manager.py::test_load_me_now PASSED                    [ 38%]
[    4s] tests/test_plugin_manager.py::test_load_me_now_exception FAILED          [ 41%]
[    4s] tests/test_plugin_manager.py::test_load_me_now_no_key_found FAILED       [ 45%]
[    4s] tests/test_plugin_manager.py::test_dynamic_load_library PASSED           [ 48%]
[    4s] tests/test_plugin_manager.py::test_dynamic_load_library_no_action PASSED [ 51%]
[    4s] tests/test_plugin_manager.py::test_register_a_plugin FAILED              [ 54%]
[    4s] tests/test_plugin_manager.py::test_get_a_plugin PASSED                   [ 58%]
[    4s] tests/test_plugin_manager.py::test_register_class PASSED                 [ 61%]
[    4s] tests/test_plugin_manager.py::test_load_me_later_function PASSED         [ 64%]
[    4s] tests/test_plugin_manager.py::test_do_import_cls_error PASSED            [ 67%]
[    4s] tests/test_plugin_manager.py::test_register_a_plugin_function_1 PASSED   [ 70%]
[    4s] tests/test_plugin_manager.py::test_register_a_plugin_function_2 PASSED   [ 74%]
[    4s] tests/test_plugin_manager.py::test_primary_key PASSED                    [ 77%]
[    4s] tests/test_plugin_manager.py::test_dict_as_plugin_payload PASSED         [ 80%]
[    4s] tests/test_plugin_manager.py::test_show_me_your_name PASSED              [ 83%]
[    4s] tests/test_utils.py::test_json_dumps PASSED                              [ 87%]
[    4s] tests/test_utils.py::test_do_import FAILED                               [ 90%]
[    4s] tests/test_utils.py::test_do_import_2 PASSED                             [ 93%]
[    4s] tests/test_utils.py::test_do_import_error PASSED                         [ 96%]
[    4s] tests/test_utils.py::test_do_import_cls PASSED                           [100%]
[    4s] 
[    4s] =================================== FAILURES ===================================
[    4s] ______________________________ test_load_plugins _______________________________
[    4s] 
[    4s] pkgutil_iter_modules = <MagicMock name='iter_modules' id='139747258398176'>
[    4s] pkgutil_get_importer = <MagicMock name='get_importer' id='139747258868544'>
[    4s] 
[    4s]     @patch("pkgutil.get_importer")
[    4s]     @patch("pkgutil.iter_modules")
[    4s]     def test_load_plugins(pkgutil_iter_modules, pkgutil_get_importer):
[    4s]         test_module_name = "pyexcel_test"
[    4s]         sample_toc = set(["pyexcel_io"])
[    4s]         pkgutil_get_importer.return_value.toc = sample_toc
[    4s]         pkgutil_iter_modules.return_value = [("not used", test_module_name, True)]
[    4s]         from lml.loader import scan_plugins
[    4s]     
[    4s]         scan_plugins("pyexcel_", ".", ["pyexcel_io"])
[    4s]         from lml.plugin import CACHED_PLUGIN_INFO
[    4s]     
[    4s] >       info = CACHED_PLUGIN_INFO["test_io"][0]
[    4s] E       IndexError: list index out of range
[    4s] 
[    4s] tests/test_plugin_loader.py:38: IndexError
[    4s] ------------------------------ Captured log call -------------------------------
[    4s] ERROR    lml.utils:utils.py:44 pyexcel_test is abscent or cannot be imported
[    4s] Traceback (most recent call last):
[    4s]   File "/home/abuild/rpmbuild/BUILDROOT/python-lml-0.0.9-0.x86_64/usr/lib/python3.8/site-packages/lml/utils.py", line 42, in do_import
[    4s]     return _do_import(plugin_module_name)
[    4s]   File "/home/abuild/rpmbuild/BUILDROOT/python-lml-0.0.9-0.x86_64/usr/lib/python3.8/site-packages/lml/utils.py", line 51, in _do_import
[    4s]     plugin_module = __import__(plugin_module_name)
[    4s] ModuleNotFoundError: No module named 'pyexcel_test'
[    4s] ____________________ test_load_plugins_without_pyinstaller _____________________
[    4s] 
[    4s] pkgutil_iter_modules = <MagicMock name='iter_modules' id='139747258935520'>
[    4s] pkgutil_get_importer = <MagicMock name='get_importer' id='139747259358800'>
[    4s] 
[    4s]     @patch("pkgutil.get_importer")
[    4s]     @patch("pkgutil.iter_modules")
[    4s]     def test_load_plugins_without_pyinstaller(
[    4s]         pkgutil_iter_modules, pkgutil_get_importer
[    4s]     ):
[    4s]         test_module_name = "pyexcel_test"
[    4s]         sample_toc = set()
[    4s]         pkgutil_get_importer.return_value.toc = sample_toc
[    4s]         # mock iter modules
[    4s]         pkgutil_iter_modules.return_value = [("not used", test_module_name, True)]
[    4s]         from lml.loader import scan_plugins
[    4s]     
[    4s]         scan_plugins("pyexcel_", ".", ["pyexcel_io"])
[    4s]         from lml.plugin import CACHED_PLUGIN_INFO
[    4s]     
[    4s] >       info = CACHED_PLUGIN_INFO["test_io"][0]
[    4s] E       IndexError: list index out of range
[    4s] 
[    4s] tests/test_plugin_loader.py:58: IndexError
[    4s] ------------------------------ Captured log call -------------------------------
[    4s] ERROR    lml.utils:utils.py:44 pyexcel_test is abscent or cannot be imported
[    4s] Traceback (most recent call last):
[    4s]   File "/home/abuild/rpmbuild/BUILDROOT/python-lml-0.0.9-0.x86_64/usr/lib/python3.8/site-packages/lml/utils.py", line 42, in do_import
[    4s]     return _do_import(plugin_module_name)
[    4s]   File "/home/abuild/rpmbuild/BUILDROOT/python-lml-0.0.9-0.x86_64/usr/lib/python3.8/site-packages/lml/utils.py", line 51, in _do_import
[    4s]     plugin_module = __import__(plugin_module_name)
[    4s] ModuleNotFoundError: No module named 'pyexcel_test'
[    4s] __________________________ test_load_me_now_exception __________________________
[    4s] 
[    4s] mock_import = <MagicMock name='do_import_class' id='139747258465056'>
[    4s] 
[    4s]     @patch("lml.plugin.do_import_class")
[    4s]     def test_load_me_now_exception(mock_import):
[    4s]         custom_class = PluginInfo
[    4s]         mock_import.return_value = custom_class
[    4s]         test_plugin = "my plugin"
[    4s]         with raises(Exception):
[    4s]             manager = PluginManager(test_plugin)
[    4s] >           plugin_info = make_me_a_plugin_info("my")
[    4s] E           Failed: DID NOT RAISE <class 'Exception'>
[    4s] 
[    4s] tests/test_plugin_manager.py:47: Failed
[    4s] ________________________ test_load_me_now_no_key_found _________________________
[    4s] 
[    4s]     def test_load_me_now_no_key_found():
[    4s]         test_plugin = "my plugin"
[    4s]         with raises(Exception):
[    4s] >           manager = PluginManager(test_plugin)
[    4s] E           Failed: DID NOT RAISE <class 'Exception'>
[    4s] 
[    4s] tests/test_plugin_manager.py:55: Failed
[    4s] ____________________________ test_register_a_plugin ____________________________
[    4s] 
[    4s]     def test_register_a_plugin():
[    4s]         test_plugin = "test plugin"
[    4s]     
[    4s]         manager = PluginManager(test_plugin)
[    4s]         plugin_info = make_me_a_plugin_info("my")
[    4s]         manager.register_a_plugin(TestClass, plugin_info)
[    4s] >       assert plugin_info.cls == TestClas
[    4s] E       NameError: name 'TestClas' is not defined
[    4s] 
[    4s] tests/test_plugin_manager.py:90: NameError
[    4s] ________________________________ test_do_import ________________________________
[    4s] 
[    4s]     def test_do_import():
[    4s] >       import pyexcel_test
[    4s] E       ModuleNotFoundError: No module named 'pyexcel_test'
[    4s] 
[    4s] tests/test_utils.py:17: ModuleNotFoundError
[    4s] =============================== warnings summary ===============================
[    4s] tests/test_plugin_loader.py::test_load_plugins
[    4s] tests/test_plugin_loader.py::test_load_plugins_without_pyinstaller
[    4s] tests/test_plugin_loader.py::test_load_plugins_without_any_plugins
[    4s] tests/test_plugin_loader.py::test_load_plugins_without_black_list
[    4s] tests/test_plugin_loader.py::test_load_plugins_import_error
[    4s]   /home/abuild/rpmbuild/BUILDROOT/python-lml-0.0.9-0.x86_64/usr/lib/python3.8/site-packages/lml/loader.py:63: UserWarning: Deprecated! since version 0.0.3. Please use scan_plugins_regex!
[    4s]     warnings.warn(
[    4s] 
[    4s] -- Docs: https://docs.pytest.org/en/latest/warnings.html
[    4s] =========================== short test summary info ============================
[    4s] FAILED tests/test_plugin_loader.py::test_load_plugins - IndexError: list inde...
[    4s] FAILED tests/test_plugin_loader.py::test_load_plugins_without_pyinstaller - I...
[    4s] FAILED tests/test_plugin_manager.py::test_load_me_now_exception - Failed: DID...
[    4s] FAILED tests/test_plugin_manager.py::test_load_me_now_no_key_found - Failed: ...
[    4s] FAILED tests/test_plugin_manager.py::test_register_a_plugin - NameError: name...
[    4s] FAILED tests/test_utils.py::test_do_import - ModuleNotFoundError: No module n...
[    4s] =================== 6 failed, 25 passed, 5 warnings in 0.18s ===================
[    4s] error: Bad exit status from /var/tmp/rpm-tmp.cMrCdM (%check)

Any idea, how to make this pull request work, please?

bmwiedemann added a commit to bmwiedemann/openSUSE that referenced this pull request Aug 14, 2020
https://build.opensuse.org/request/show/824848
by user mcepl + dimstar_suse
- Add remove_nose.patch (gh#python-lml/lml#19), which
  unfortunately is still WIP, so we have to remove switch off
  tests for now.
@chfw
Copy link
Collaborator

chfw commented Sep 26, 2020

Let me have a look.

I am sorry for the late reply!

@chfw chfw merged commit 4d996c8 into python-lml:dev Sep 26, 2020
@mcepl mcepl deleted the remove_nose branch September 27, 2020 00:31
This was referenced Oct 18, 2020
@chfw
Copy link
Collaborator

chfw commented Oct 19, 2020

Soon this project will be converted fully to pytest.

@chfw chfw mentioned this pull request Oct 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants