Tests pass locally but fails on the server

Hi colleagues,

It seems that we are using the outdated version in our test runner.

How about updating the version to the latest one?

We received the following error when we ran your code:
  .usr.local.lib.python3.11.site-packages._pytest.python.py:618: in _importtestmodule
    mod = import_path(self.path, mode=importmode, root=self.config.rootpath)
.usr.local.lib.python3.11.site-packages._pytest.pathlib.py:533: in import_path
    importlib.import_module(module_name)
.usr.local.lib.python3.11.importlib.__init__.py:126: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
<frozen importlib._bootstrap>:1204: in _gcd_import
    ???
<frozen importlib._bootstrap>:1176: in _find_and_load
    ???
<frozen importlib._bootstrap>:1147: in _find_and_load_unlocked
    ???
<frozen importlib._bootstrap>:690: in _load_unlocked
    ???
.usr.local.lib.python3.11.site-packages._pytest.assertion.rewrite.py:168: in exec_module
    exec(co, module.__dict__)
.mnt.exercism-iteration.saddle_points_test.py:7: in <module>
    from saddle_points import (
E     File ".mnt.exercism-iteration.saddle_points.py", line 1
E       type Matrix = list[list[int]]
E            ^^^^^^
E   SyntaxError: invalid syntax

Hi @rabestro :wave:

Three things here:

  1. We don’t use type hints or type alias on Exercism. They are optional and not required/are ignored by the Python interpreter and we don’t have curriculum, exercises, or tests for them. So we often recommend students leave them out of their code and/or find another place or method (like using mypy) to practice them.

  2. There was a syntax change for type aliases between Python 3.11.5 and Python 3.13. Python 3.11.5 doesn’t have a type keyword, Python 3.13 does. Your syntax error (and test failure) can be corrected by omitting the type keyword and leaving the type alias declarations in the code. I tried it locally on both my 3.11.5 env (3.11.5 with pytest 7.2) and my 3.13.5 env (3.13.5 with pytest 8.4) and all tests passed. So using the type keyword is unnecessary in either version of Python.

  3. Python 3.11.5 is far from “outdated”. Many production systems aren’t even on Python 3.11.5 yet — 3.8 just went EOL, and there is a LOT of Python 3.8/3.9 out there. Upgrading is on the list for Exercism, but I am not going to rush it because of type aliases or type hinting. There are other tools that also need to be upgraded, some bugs in tooling to be fixed, and quite a bit of testing to do. You will have to be patient with us for a bit. :slightly_smiling_face:

4 Likes

Hi @BethanyG

Thank you for such a detailed explanation! For me personally, this is not a problem as soon as I can pass the all tests locally. I hope the Python track starts using type hinting in future versions. I found this feature helpful and I use it in all my solutions.

Cheers, Jegors

Hey @BethanyG
Is it ok if I prepare pull request with python upgrade?

1 Like

Hi @rabestro,

Short answer? No.

Thank you so much for offering (and for wanting to volunteer for Exercism!) but it is not OK to do a PR for a Python upgrade.

The upgrade is tied to tooling, testing, CI, and a bunch of other changes that go across all three tooling repos as well as the content repo. And some of them overlap or depend on one another.

There are multiple alterations and bug fixes that I am currently working through. While it’s not hard, it is complicated/time consuming, and does require a lot of knowledge of how the different Exercism bits fit together. We will also still support Python 3.9 & 3.10 (after dropping 3.8), so there are library complications as well. And quite a few things to clean up in our generation and testing scripts.

While Python is generally closed to community contribution; if after the upgrade you are still interested in contributing to the Python track, we can (perhaps) talk about adding some practice or concept exercises or approaches docs.

But for the next while, I need to focus on the upgrades and refactoring myself. :slightly_smiling_face:

3 Likes