0

I'd like to prevent/skip some tests cases during runinng others in python. I couldn't achive to use @unittest.skip(reason) on my case. It always generates a Script Error in python unittest.

My code;

import unittest
@unittest.skip("something")
def main():
    
    try:
        something = []
        for _ in range(4):
             test.log("something happened")

The result is;

Error Script Error 
    Detail: SkipTest: something

Do you have any idea about the issue?

Erol Erdogan
  • 128
  • 9
  • Is `main` a test function, or a function you're testing? `unittest.skip` should be applied on a test function. Also, what is `test`, and is there anything else in the `main` function? – decorator-factory Jun 02 '22 at 11:33
  • It's a main test of test case. I have a different structure actually. For instance, I have 10 test cases seperately (means 10 different files) and both of the are written under main funtion. And test is library of Squish IDE. It is not important for this case. – Erol Erdogan Jun 02 '22 at 12:17

2 Answers2

0

Unittest is a module that act as testing framework. You should use it according to the framework practices (taken from tutorialspoint.com):

import unittest

   def add(x,y):
      return x+y

class SimpleTest(unittest.TestCase):
   @unittest.skip("demonstrating skipping")
   def testadd1(self):
      self.assertEquals(add(4,5),9)

if __name__ == '__main__':
   unittest.main()
AutomatedOwl
  • 1,039
  • 1
  • 8
  • 14
  • I've already tried this. But unfortunately, it's not working in my case. Because I don't have class structure. My codes directly start with; def main(): – Erol Erdogan Jun 02 '22 at 13:47
  • as far as I know the framework, by definition, you cannot use unittest without a class structure – AutomatedOwl Jun 04 '22 at 17:10
  • maybe this is the reason that I cannot use skip methods of unittest library in my framework unfortunately – Erol Erdogan Jun 08 '22 at 10:53
0

Squish test scripts written in Python are unrelated to the unittest module. I cannot tell how the two could be used together.

Squish offers the test.skip() function for skipping test cases:

test.skip(message);

test.skip(message, detail);

This function skips further execution of the current script test case, or the current BDD scenario (or BDD scenario outline iteration), by throwing an exception and adding a SKIPPED entry to Squish's test log with the given message string, and with the given detail, if provided. If the test case logged verification failures before the skip, it is still considered failed.

frog.ca
  • 684
  • 4
  • 8