Unittest - Test is reported as UntitledTestCase
gileli121 opened this issue · comments
Expected Behavior
After I execute the unittest class, I expected to see one job in the cloud report with 2 tests inside, each test have the name of it's method name.
Current Behavior
After the unittest class finished to execute, the report I got is the execution of 2 jobs, each job have one test case with name UntitledTestCase
(and not the name of the method)
Possible Solution
I don't know about any work around for this. If I want to recreate the driver before each test, I don't have any options.
Steps to Reproduce
Try to run the code:
import unittest
from src.testproject.sdk.drivers import webdriver
class UntitledTestCase(unittest.TestCase):
def setUp(self):
self.driver = webdriver.Chrome(jobname="Job with multiple tests")
def tearDown(self):
self.driver.quit()
def test_untitled_test_case1(self):
self.driver.get("http://google.com")
def test_untitled_test_case2(self):
self.driver.get("http://yahoo.com")
if __name__ == "__main__":
unittest.main()
Context (Environment)
Windows 10
Agent 0.63.1
Latest SDK version
Looking into this right now. Seems like the logic to derive the current test name when we're using unittest
is not perfect yet.
@gileli121 how do you run your tests in this case? Please do this either by invoking the if __name__=="__main__"
bit in your IDE or via the command line: python -m unittest <your_test_module>
. Only then will unittest
do proper test discovery.
The result on my end looks different from yours:
Still not good but I know what is wrong here :) I've seen your results too, but that happens only when you run the test method directly from your IDE without invoking unittest
and its test discovery mechanism properly.
I don't have if __name__=="__main__"
I use the IDE to run the test method directly.
I should not do it?
No, I've noticed that unittest will not properly discover test methods in that case. Please add it so unittest can discover tests properly.
The first example on the official docs also has it: https://docs.python.org/3/library/unittest.html
I did this:
It was pytest
selected before.
After that, I clicked the play button on the class (not the method)
I get now the exact result you showed in #3 (comment)
Ah, yes, that helps, too :)
I've already created a fix for this, just a bit more testing and I'll create rc4
Just finished testing the fix, it reports the tests now as expected in the example you gave.
It also reports this:
import unittest
from src.testproject.sdk.drivers import webdriver
class UntitledTestCase(unittest.TestCase):
driver = None
@classmethod
def setUpClass(cls):
cls.driver = webdriver.Chrome(jobname="Job with multiple tests")
@classmethod
def tearDownClass(cls):
cls.driver.quit()
def test_untitled_test_case1(self):
self.driver.get("http://google.com")
def test_untitled_test_case2(self):
self.driver.get("http://yahoo.com")
if __name__ == "__main__":
unittest.main()
As a single job with two tests (because the driver is initialized only once).
https://test.pypi.org/project/testproject-python-sdk/0.63.10rc4/ is live, please retest with this version
@basdijkstra, it is better now. But I still get 2 jobs - each one with another test.
Unlike before, this is the only issue here.
Update:
Same issue for code:
import pytest
from src.testproject.sdk.drivers.webdriver import Chrome
@pytest.fixture
def driver():
# Will be executed before the first test
driver = Chrome(projectname="python sdk project",
jobname="before_after_each",
disable_reports=False)
yield driver
# Will be executed after the last test
driver.quit()
def test_some_test_case_1(driver):
driver.get("http://google.com/")
def test_some_test_case_2(driver):
driver.get("http://yahoo.com/")
if __name__ == "__main__":
pytest.main()
@gileli121 could you please retest this for unittest
after #18 has been released?
ok
The issue about the test name was fixed.
The second issue is not an issue but it is an enhancement according to @mstrelex
So I will close this issue and open another issue as an enhancement.