After and update and some project import, somethign very weird happens to my tests once run from Pycharm. I already fixed the general unittest runner config, but I am not being able to do it when running single testes, both in config and just with right click, which is quite confortable.
Very simple example code:
import unittest
class TestTheTester(unittest.TestCase):
@classmethod
def setUpClass(cls) -> None:
cls.name = "TestTheTester"
def test_unittest(self):
self.assertEqual("TestTheTester", self.name)
Runing it from the Shell:
python3 -m unittest tests/test_the_tester.py
.
----------------------------------------------------------------------
Ran 1 test in 0.000s
OK
Running it from PyCharm doing right-click on it (option "Run 'Python test in tests...'):
/usr/bin/python3.8 /snap/pycharm-community/252/plugins/python-ce/helpers/pycharm/_jb_trialtest_runner.py --path /home/user123/development/Project456/tests/test_the_tester.py
Testing started at 10:26 ...
Launching trial with arguments --reporter=teamcity /home/user123/development/Project456/tests/test_the_tester.py in /home/user123/development/Project456/tests/
Error
Traceback (most recent call last):
Failure: builtins.tuple: (<class 'AttributeError'>, AttributeError("'TestTheTester' object has no attribute 'name'"), <traceback object at 0x7fc59e432f00>)
The Run/Debug Configuration it creates is:
- 'Python tests' one
- Autodetect's Target '
Script path' to/home/user123/development/Project456/tests/test_the_tester.py - Python interpreter
Project Default(/usr/bin/python3.8) - Workign directory
/home/user123/development/Project456/tests/ - Both options 'Add content roots to PYTHONPATH' and 'Add source roots to PUTHONPATH' selected