Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #78611
| Newsgroups | comp.lang.python |
|---|---|
| Date | 2014-10-02 08:30 -0700 |
| References | <eaf17169-25d1-4022-a8de-3b0d6fd9afb8@googlegroups.com> |
| Message-ID | <b94e6437-3035-454e-a5ea-0a5b452a3410@googlegroups.com> (permalink) |
| Subject | Re: Python unittesting method call issue |
| From | Milson Munakami <milsonmun@gmail.com> |
On Saturday, September 27, 2014 5:26:00 PM UTC-6, Milson Munakami wrote:
> I am trying to set the precondition for the test first prior to test other test cases. But as you can see in my code the precondition print command is not fired! Can you explain the cause and solution how to fire the code with in that method i.e. SetPreConditionFirewall() with setup variable self.<variablename> in this fucntion. Here is my code:
>
>
>
> import json
>
> import urllib
>
> #import time
>
> #from util import *
>
> import httplib
>
>
>
> #import sys
>
> #from scapy.all import *
>
>
>
> import unittest
>
>
>
> import os, sys, socket, struct, select, time
>
> from threading import Thread
>
>
>
> import logging
>
> import traceback
>
>
>
> class testFirewallS1( unittest.TestCase ):
>
> def setUp(self):
>
> self.controllerIp="127.0.0.1"
>
> def tearDown(self):
>
> if self.failed:
>
> return
>
> duration = time.time() - self.startTime_
>
> self.cleanup(True)
>
> if self.reportStatus_:
>
> self.log.info("=== Test %s completed normally (%d sec)", self.name_, duration)
>
>
>
> def cleanup(self, success):
>
> sys.excepthook = sys.__excepthook__
>
> try:
>
> return
>
> except NameError:
>
> self.log.error("Exception hit during cleanup, bypassing:\n%s\n\n" % traceback.format_exc())
>
> pass
>
> else:
>
>
>
> fail("Expected a NameError")
>
>
>
> def SetPreConditionFirewall(self):
>
> command = "http://%s:8080/wm/firewall/module/enable/json" % self.controllerIp
>
> urllib.urlopen(command).read()
>
> print self.controllerIp
>
> print "Test Pre-condition setting here"
>
>
>
> #Precondition Test
>
> def testPreConditionFirewall(self):
>
> print "Test pass"
>
>
>
> def suite():
>
>
>
> suite = unittest.TestSuite()
>
>
>
> suite.addTest(unittest.makeSuite(testFirewallS1))
>
>
>
> return suite
>
>
>
>
>
> if __name__ == '__main__':
>
>
>
> suiteFew = unittest.TestSuite()
>
>
>
> testFirewallS1("SetPreConditionFirewall")
>
>
>
> suiteFew.addTest(testFirewallS1("testPreConditionFirewall"))
>
>
>
>
>
> #Testing the Test Cases Begins Here
>
> unittest.TextTestRunner(verbosity=2).run(suiteFew)
>
>
>
> How can I do access that method on __main__ and how can that method can access the setup variable.
>
>
>
> Thanks
Thanks :)
Back to comp.lang.python | Previous | Next — Previous in thread | Find similar | Unroll thread
Python unittesting method call issue Milson Munakami <milsonmun@gmail.com> - 2014-09-27 16:25 -0700 Re: Python unittesting method call issue Chris Angelico <rosuav@gmail.com> - 2014-09-28 09:42 +1000 Re: Python unittesting method call issue Ian Kelly <ian.g.kelly@gmail.com> - 2014-09-27 18:27 -0600 Re: Python unittesting method call issue Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-09-28 12:19 +1000 Re: Python unittesting method call issue Milson Munakami <milsonmun@gmail.com> - 2014-10-02 08:30 -0700
csiph-web