How to use test_works method in hypothesis

Best Python code snippet using hypothesis

regression_tester.py

Source:regression_tester.py Github

copy

Full Screen

1#!/usr/bin/env python2"""Tool for checking if patch contains a regression test.3Pass in gerrit review number as parameter, tool will download branch and run4modified tests without bug fix.5"""6import string7import subprocess8import sys9gerrit_number = None10#TODO(jogo) use proper optParser11if len(sys.argv) == 2:12 gerrit_number = sys.argv[1]13else:14 gerrit_number = None15 print ("no gerrit review number specified, running on latest commit"16 "on current branch.")17def run(cmd, fail_ok=False):18 print "running: %s" % cmd19 try:20 rval = subprocess.check_output(cmd, shell=True)21 except subprocess.CalledProcessError:22 if not fail_ok:23 print "The command above terminated with an error."24 sys.exit(1)25 pass26 return rval27test_works = False28if gerrit_number:29 original_branch = run("git rev-parse --abbrev-ref HEAD")30 run("git review -d %s" % gerrit_number)31# run new tests with old code32run("git checkout HEAD^ nova")33run("git checkout HEAD nova/tests")34# identify which tests have changed35tests = run("git whatchanged --format=oneline -1 | grep \"nova/tests\" "36 "| cut -f2").split()37test_list = []38for test in tests:39 test_list.append(string.replace(test[0:-3], '/', '.'))40if test_list == []:41 test_works = False42 expect_failure = ""43else:44 # run new tests, expect them to fail45 expect_failure = run(("tox -epy27 %s 2>&1" % string.join(test_list)),46 fail_ok=True)47 if "FAILED (id=" in expect_failure:48 test_works = True49# cleanup50run("git checkout HEAD nova")51if gerrit_number:52 new_branch = run("git status | head -1 | cut -d ' ' -f 4")53 run("git checkout %s" % original_branch)54 run("git branch -D %s" % new_branch)55if test_works:56 print expect_failure57 print ""58 print "*******************************"59 print "FOUND a regression test"60else:61 print expect_failure62 print ""63 print "*******************************"64 print "NO regression test"...

Full Screen

Full Screen

test.py

Source:test.py Github

copy

Full Screen

1import unittest2import petname3import petname.english4class TestAdjective(unittest.TestCase):5 def test_works(self):6 self.assertIn(petname.adjective(), petname.english.adjectives)7 def test_alias(self):8 self.assertIs(petname.adjective, petname.Adjective)9 def test_len(self):10 for l in range(4, 10):11 self.assertLessEqual(len(petname.adjective(l)), l)12class TestAdverb(unittest.TestCase):13 def test_works(self):14 self.assertIn(petname.adverb(), petname.english.adverbs)15 def test_alias(self):16 self.assertIs(petname.adverb, petname.Adverb)17 def test_len(self):18 for l in range(4, 10):19 self.assertLessEqual(len(petname.adverb(l)), l)20class TestName(unittest.TestCase):21 def test_works(self):22 self.assertIn(petname.name(), petname.english.names)23 def test_alias(self):24 self.assertIs(petname.name, petname.Name)25 def test_len(self):26 for l in range(4, 10):27 self.assertLessEqual(len(petname.name(l)), l)28class TestGenerate(unittest.TestCase):29 def test_works(self):30 words = 331 sep = '-'32 name = petname.generate(words, sep)33 self.assertEqual(len(name.split(sep)), words)34 def test_alias(self):35 self.assertIs(petname.generate, petname.Generate)36if __name__ == '__main__':...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run hypothesis automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful