D&D Character test bug

It seems that there is a problem with testing script of problem. Whenever I run my code, it says the following:

We received the following error when we ran your code:

  ImportError while importing test module '.mnt.exercism-iteration.dnd_character_test.py'.
Hint: make sure your test modules.packages have valid Python names.
Traceback:
.usr.local.lib.python3.11.importlib.__init__.py:126: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
.mnt.exercism-iteration.dnd_character_test.py:7: in <module>
    from dnd_character import (
E   ImportError: cannot import name 'modifier' from 'dnd_character' (.mnt.exercism-iteration.dnd_character.py)

Would someone please have a look at this?

Did you delete the modifier function from the file? The file is supposed to contain a modifier function.

Hi @stt106 :wave:

TL;DR The tests are not incorrect, but we didn’t give you as much information about how to structure your solution as we might have.

If you look at the last line of the error:

E   ImportError: cannot import name 'modifier' from 'dnd_character' (.mnt.exercism-iteration.dnd_character.py)

– the test runner is looking to import a function named modifier (see these lines in the test file) . Since that function doesn’t exist in your solution, the test runner bails out, and the tests fail to run.

I just took a look at the stub file for this exercise and realized that we did not include a function stub for modifier(value). The addition to the stub would look something like this:

class Character:
    def __init__(self):
        pass

def modifier(value):
    pass

Not sure if I want to change the stub, or add and instruction.append and hint.md files here, since reading the test file and the test failures is important learning for students.

I will think on it and PR a fix to either the stub or hint files later today, and possibly add an instruction append for clarity.

3 Likes

Hi sorry but I meant there is a problem running the tests.
The instruction wasn’t clear on implementing a modifier(value) function. I thought it’s only required to implement a Character class.

I didn’t delete it as I never had one.
Didn’t realize it requires to implement such a function. I thought it only needs to implement a Character class.

Ok this is now resolved once I realize I need to implement a modifier function in addition to a Character class.
I was confused initially because the file has only defined an empty class and I thought all what’s required was implementing that class.

1 Like

Perhaps that’s why the modifier() placeholder was removed in this commit. BTW, it was quite confusing, but this thread helped me solve the problem.

I think it is very helpful to add comments to the students stub file, that an exercise does not provide all functions / methods / structures required. It is also a clear sign to contributors, that it is intended like this and PRs to “fix it” will be rejected.

2 Likes