First of all if I didn't formulat the question in a correct way, Sorry I tried my best.
I made a question an hour ago, but it was not in English, and to make another question I had to wait 40min. However my question was: how can I make a class that inside has test cases using pytest
I did my research and I found a code that matches what I want, however it doesn't use pytest, instead it uses unittest, if I didn't explain myself I will let the code that I found if it helps as an example:
import unittest
class TestStringMethods(unittest.TestCase):
def test_upper(self):
self.assertEqual('foo'.upper(), 'FOO')
def test_isupper(self):
self.assertTrue('FOO'.isupper())
self.assertFalse('Foo'.isupper())
def test_split(self):
s = 'hello world'
self.assertEqual(s.split(), ['hello', 'world'])
# check that s.split fails when the separator is not a string
with self.assertRaises(TypeError):
s.split(2)
if __name__ == '__main__':
unittest.main()
In the code that I included, it uses Unittest and it takes unitest.TeslaCase as argument. Is there any way to do it with pytest?, that instead of using unittest I could use pytest?
Thanks in advance!!
class Test_StringMethods():
def test_upper(self):
assert ('foo'.upper() == 'FOO'), "FAILED"
def test_isupper(self):
assert 'FOO'.isupper(), "FAILED"
assert not 'Foo'.isupper(), "FAILED"
def test_split(self):
s = 'hello world'
assert s.split() == ['hello', 'world'], "FAILED"
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.