Bug 8483

Summary: Compatible to run generic pyunit test cases by test runner
Product: [QA/Testing] Runtime Testing Reporter: Cathy Shen <cathy.shen>
Component: generalAssignee: jingwang <jing.j.wang>
Status: RESOLVED OBSOLETE QA Contact:
Severity: enhancement    
Priority: Medium CC: alexandru.c.georgescu, benjamin.esquivel, bill.randle, costin.c.constantin, jing.j.wang, mariano.lopez, richard.purdie
Version: 2.1   
Target Milestone: Future   
Hardware: x86   
OS: Multiple   
Whiteboard:
OS type for building Yocto: --- Type of Regression: ---
Verified: Documentation change: Don't know

Description Cathy Shen 2015-10-12 01:10:24 UTC
Lots of test cases are generic pyunit based cases,that means no Yocto modules or classes are imported in test cases. For this kind of test cases, we'd like to run by oeRuntime test runner, and get proper test result and log as well.
Comment 1 Costin 2015-10-12 13:17:21 UTC
Hi Cathy,

Isn't this related to YP#8483. 

Thankyou,

Costin
Comment 2 Cathy Shen 2015-10-13 05:46:14 UTC
This is YP#8483 actually. :)
Comment 3 Costin 2015-10-13 10:29:34 UTC
Hi Cathy,

Apologies for earlier comment. I meant YP#8479 but don't think is that related now after your comment there.

If i understand correct you would like to have a file mytest.py that contains?

import unittest

class mytests(unittest.TestCase):
  def test_something(self):
    ...# the effective work here
    self.assertEqual(command_status, 0, msg = "something went wrong")


If so, oeRuntimeTest already inherits unittest and assures transparent communication with DUT.
Comment 4 Costin 2015-10-13 12:11:56 UTC
Hi Cathy,

I just wrote a very simple PyUnit testcase:

ubnt:/opt/poky-lsb/2.0/exported_tests/oeqa/runtime# cat some_test.py

import unittest

class testsomething(unittest.TestCase):
    def test_sometest(self):
        a=5
        self.assertEqual(5, a, msg = "not equal")

added the test file to the testslist in testdata.json:
    "testslist": [
        "oeqa.runtime.some_test"
    ],
and than ran ./runexported.py:
ubnt:/opt/poky-lsb/2.0/exported_tests# ./runexported.py 
SSH log file: /opt/poky-lsb/2.0/exported_tests/ssh_target_log.20151013121526
test_sometest (oeqa.runtime.some_test.testsomething) ... ok

----------------------------------------------------------------------
Ran 1 test in 0.000s

OK

Does this suffices your needs?
I would like to emphasize here that without inheriting oeRuntimeTest no target controller was used and thus the test itself 
was ran on the machine intended to launch tests against DUTs. It means the test file itself needs to implement (or inherit from somewhere) test delivery on DUT.

Costin
Comment 5 jingwang 2015-10-28 05:06:23 UTC
Zephyr TC handle target controller via TC itself, not via test runner. Thus, it is good that runexported can execute raw python unittest TC.
Comment 6 Costin 2015-10-29 15:05:03 UTC
Hi Cathy,

As said,in order to use runexported.py at this moment as it is available on master, please follow indications from here:
http://www.yoctoproject.org/docs/current/mega-manual/mega-manual.html#exporting-tests
Comment 7 Cathy Shen 2015-11-24 00:44:30 UTC
Hi Costin, thanks for the information. I think we can close this ticket since generic pytest is supported. What do you think?
Comment 8 jingwang 2015-11-24 01:05:16 UTC
I take a look at the code, although pristine Pyunit is workable, it actually go through some unnecessary steps, see below. 
******************************************
def loadTests(tc, type="runtime"):
    if type == "runtime":
        # set the context object passed from the test class
        setattr(oeTest, "tc", tc)
        # set ps command to use
        setattr(oeRuntimeTest, "pscmd", "ps -ef" if oeTest.hasPackage("procps") else "ps")
        # prepare test suite, loader and runner
        suite = unittest.TestSuite()
    elif type == "sdk":
        # set the context object passed from the test class
        setattr(oeTest, "tc", tc)
    testloader = unittest.TestLoader()
    testloader.sortTestMethodsUsing = None
    suites = [testloader.loadTestsFromName(name) for name in tc.testslist]
    suites = filterByTagExp(suites, getattr(tc, "tagexp", None))
***************************************
Comment 9 jingwang 2015-11-24 01:11:06 UTC
I suggest keep this feature/bug pending, and assign to me. I am working on a complete solution to resolve common testrunner features and project specific features.
Comment 10 Cathy Shen 2015-11-24 06:10:28 UTC
I'm OK with this. Assign to WangJing and mark it as IN PROGRESS DESIGN. Costin, let me know if you have any concern.
Comment 11 Benjamin Esquivel 2016-07-11 17:08:14 UTC
Talking with the owner of this bug, seems like it can be finished by 2.2 M3.
Comment 12 Richard Purdie 2018-08-09 15:29:19 UTC
We completed the testexport work and the exact other deliverables are unclear. Closing as obsolete to be replaced with any specific bugs for other issues.