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

Tests fail to run on Python 3.10 due to nose incompatibility #343

Closed
rileyjmurray opened this issue Sep 5, 2023 · 3 comments · Fixed by #344
Closed

Tests fail to run on Python 3.10 due to nose incompatibility #343

rileyjmurray opened this issue Sep 5, 2023 · 3 comments · Fixed by #344
Labels
bug A bug or regression

Comments

@rileyjmurray
Copy link
Contributor

Describe the bug

The file test/runTests.py has a codepath that executes a shell command. The shell command requires the Python testing framework called nose. Unfortunately, nose is no longer maintained, and it broke starting with Python 3.9 (see here). So if you try to run python runTests.py in the test folder you'll get an error before any tests run.

To Reproduce

  1. change directory so you're in the test folder.
  2. run python runTests.py
  3. Get output below.
Running tests:
tools
iotest
objects
construction
drivers
report
reportb
algorithms
algorithmsb
optimize
extras
mpi
python3.10 -m nose -v tools iotest objects construction drivers report reportb algorithms algorithmsb optimize extras mpi --with-id
Traceback (most recent call last):
  File "/Users/riley/miniforge3/envs/gsti310/lib/python3.10/runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/Users/riley/miniforge3/envs/gsti310/lib/python3.10/runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "/Users/riley/miniforge3/envs/gsti310/lib/python3.10/site-packages/nose/__main__.py", line 8, in <module>
    run_exit()
  File "/Users/riley/miniforge3/envs/gsti310/lib/python3.10/site-packages/nose/core.py", line 118, in __init__
    unittest.TestProgram.__init__(
  File "/Users/riley/miniforge3/envs/gsti310/lib/python3.10/unittest/main.py", line 100, in __init__
    self.parseArgs(argv)
  File "/Users/riley/miniforge3/envs/gsti310/lib/python3.10/site-packages/nose/core.py", line 179, in parseArgs
    self.createTests()
  File "/Users/riley/miniforge3/envs/gsti310/lib/python3.10/site-packages/nose/core.py", line 193, in createTests
    self.test = self.testLoader.loadTestsFromNames(self.testNames)
  File "/Users/riley/miniforge3/envs/gsti310/lib/python3.10/site-packages/nose/loader.py", line 481, in loadTestsFromNames
    return unittest.TestLoader.loadTestsFromNames(self, names, module)
  File "/Users/riley/miniforge3/envs/gsti310/lib/python3.10/unittest/loader.py", line 220, in loadTestsFromNames
    suites = [self.loadTestsFromName(name, module) for name in names]
  File "/Users/riley/miniforge3/envs/gsti310/lib/python3.10/unittest/loader.py", line 220, in <listcomp>
    suites = [self.loadTestsFromName(name, module) for name in names]
  File "/Users/riley/miniforge3/envs/gsti310/lib/python3.10/site-packages/nose/loader.py", line 431, in loadTestsFromName
    return self.loadTestsFromModule(
  File "/Users/riley/miniforge3/envs/gsti310/lib/python3.10/site-packages/nose/loader.py", line 354, in loadTestsFromModule
    tests.extend(self.loadTestsFromDir(module_path))
  File "/Users/riley/miniforge3/envs/gsti310/lib/python3.10/site-packages/nose/loader.py", line 183, in loadTestsFromDir
    yield self.loadTestsFromName(
  File "/Users/riley/miniforge3/envs/gsti310/lib/python3.10/site-packages/nose/loader.py", line 431, in loadTestsFromName
    return self.loadTestsFromModule(
  File "/Users/riley/miniforge3/envs/gsti310/lib/python3.10/site-packages/nose/loader.py", line 359, in loadTestsFromModule
    return self.suiteClass(ContextList(tests, context=module))
  File "/Users/riley/miniforge3/envs/gsti310/lib/python3.10/site-packages/nose/suite.py", line 428, in __call__
    return self.makeSuite(tests, context, **kw)
  File "/Users/riley/miniforge3/envs/gsti310/lib/python3.10/site-packages/nose/suite.py", line 475, in makeSuite
    suite = self.suiteClass(
  File "/Users/riley/miniforge3/envs/gsti310/lib/python3.10/site-packages/nose/suite.py", line 159, in __init__
    super(ContextSuite, self).__init__(tests)
  File "/Users/riley/miniforge3/envs/gsti310/lib/python3.10/site-packages/nose/suite.py", line 53, in __init__
    super(LazySuite, self).__init__()
  File "/Users/riley/miniforge3/envs/gsti310/lib/python3.10/unittest/suite.py", line 22, in __init__
    self._tests = []
  File "/Users/riley/miniforge3/envs/gsti310/lib/python3.10/site-packages/nose/suite.py", line 106, in _set_tests
    if isinstance(tests, collections.Callable) and not is_suite:
AttributeError: module 'collections' has no attribute 'Callable'

Expected behavior
Tests are launched (and ideally pass).

Environment (please complete the following information):

  • pyGSTi version 0.9.11.2
  • python version 3.10
  • macOS 13.3
@rileyjmurray rileyjmurray added the bug A bug or regression label Sep 5, 2023
@rileyjmurray
Copy link
Contributor Author

I imagine this nose issue has been on your radar for a while. Let me know if you'd like me to port things to pytest!

@sserita
Copy link
Contributor

sserita commented Sep 5, 2023

We've actually migrated a lot of our testing framework to use pytest already. If you look in .github/workflows, you'll see that both main.yml and extras.yml use pytest on the test/unit and test/test_packages directories (which are our main directories containing tests we run regularly).
That said, there are probably several places in the other test directories where nose is still being called. If you wanted to strip all those references out and replace it with pytest instead, that would be great! Relatively low priority since our GitHub workflows do work for 3.10, but also shouldn't be a big lift either.

I'll also note that we haven't run into this because I often just invoke pytest directly. One possible bugfix to this is just removing runTests.py... Although having it for convenience for users who are less used to pytest seems like a good idea.

@sserita sserita added the fixed-but-not-in-release-yet Bug has been fixed, but isn't in an official release yet (just exists on a development branch) label Sep 12, 2023
@sserita
Copy link
Contributor

sserita commented Nov 29, 2023

Closed with release of 0.9.12.

@sserita sserita closed this as completed Nov 29, 2023
@sserita sserita removed the fixed-but-not-in-release-yet Bug has been fixed, but isn't in an official release yet (just exists on a development branch) label Dec 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A bug or regression
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants