After an update and some project import, something 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 tests, both in the config and just with a right click, which is quite comfortable.
Here is a 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)
Running it from the Shell:
python3 -m unittest tests/test_the_tester.py
.
----------------------------------------------------------------------
Ran 1 test in 0.000s
OK
Running it from PyCharm by 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:
Script path' to /home/user123/development/Project456/tests/test_the_tester.pyProject Default (/usr/bin/python3.8)/home/user123/development/Project456/tests/I'm not sure you found out the solution though, I fixed the same problem after changing test files' name to start with 'test_' and initiating a class for the test in "setUp" method.
In my case, my test code which worked perfectly didn't work at all after install some libraries with the error message below:
Error
Traceback (most recent call last):
Failure: builtins.tuple:
I hope you solved the issue already!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With