sikulixX + HtmlTestRunner - continue on assert False

Asked by Asheru

Hello,

I have a script that automates a desktop app. I have the following issue:

So I want to add 80 products and check if they are added. For each one I need to search for it's name ,add it, check if it's added, delete it then search for other ones.

I have build a generic method that does this, and it requires 3 parameters: nameOfProduct,procutAddImage,checkProductAddedImage. So far so good. It looks something like this:

def addProduct(param1,param2,param3):
      try:
             #do required actions
      except:
               loggerLogMessageThatProductIsNotadded
               assert False

For all the 80 products I'm calling this method. Now in case product no.43 for ex. is not added I want the script to continue. If i'm not using 'assert False' this will work but in the report the test is shown as passed (logs are added).

I want to know if there is possible to display the test as failed if one or more products are not added and to go on with the execution.

Thanks.

Question information

Language:
English Edit question
Status:
Answered
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
RaiMan (raimund-hocke) said :
#2

You do not seem to use the stuff according to the unittest rules.

You have to organize your tests into test cases with a possible setup and teardown.
Each test case then is run independently one after the other and reveals its result to HTMLTestRunner.

Revision history for this message
Asheru (asheru93) said :
#3

But i have built the script so tests are not hardcoded. They are read from a csv and there they can be defined depending on the needs.

Revision history for this message
Asheru (asheru93) said :
#4

This above would be a test for example

Revision history for this message
RaiMan (raimund-hocke) said :
#5

--- This above would be a test for example
Might be a "test" as you see it, but it is not a test in the sense of Python unittest/HTMLTestRunner.

Please read at least a tutorial about Python unittest, to understand, what I am saying.

Revision history for this message
TestMechanic (ndinev) said :
#6

Hi Asheru,

As far as I understand you are doing data driven test
I had same issue in the past and it is solvable.

Here is two approaches I would suggest:

1. Do not "assert" in the function
  -- you can return true or false value to the main loop and store message like "test 43 failed" in var like errorsText
  -- when your main loop finish you can check if variable errosText is empty and decide what to do

2. You can generate dynamically your tests(based on your csv) to match unit test rules. In this way you will have 80 separated tests and each can pass or fail independently

I highly recommend using second approach

Revision history for this message
Asheru (asheru93) said :
#7

@TestMechanic

Hello,

I think the second approach would result also in 80 separated rows in the html test report but I have to try.

Thanks for answering.

Revision history for this message
TestMechanic (ndinev) said :
#8

Yes. It will result in 80 rows report. This is the correct way.

Can you help with this problem?

Provide an answer of your own, or ask Asheru for more information if necessary.

To post a message you must log in.