Advertisement
Guest User

Untitled

a guest
Sep 25th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.78 KB | None | 0 0
  1. import nose, sys
  2.  
  3. def test():
  4. # do something with the command line arguments
  5. print sys.argv
  6.  
  7. if __name__ == '__main__':
  8. nose.runmodule()
  9.  
  10. $ python test.py arg
  11. E
  12. ======================================================================
  13. ERROR: Failure: ImportError (No module named arg)
  14. ----------------------------------------------------------------------
  15. Traceback (most recent call last):
  16. File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/nose-0.11.1-py2.6.egg/nose/loader.py", line 368, in loadTestsFromName
  17. module = resolve_name(addr.module)
  18. File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/nose-0.11.1-py2.6.egg/nose/util.py", line 334, in resolve_name
  19. module = __import__('.'.join(parts_copy))
  20. ImportError: No module named arg
  21.  
  22. ----------------------------------------------------------------------
  23. Ran 1 test in 0.001s
  24.  
  25. FAILED (errors=1)
  26.  
  27. import sys
  28.  
  29. class test_something(object):
  30. def setUp(self):
  31. sys.argv[1] = 'arg'
  32. del sys.argv[2] # remember that -s is in sys.argv[2], see below
  33. def test_method(self):
  34. print sys.argv
  35.  
  36. [~] nosetests test_something.py -s
  37. ['/usr/local/bin/nosetests', 'arg']
  38. .
  39. ----------------------------------------------------------------------
  40. Ran 1 test in 0.001s
  41.  
  42. OK
  43.  
  44. import os
  45.  
  46. print os.getenv('KEY_THAT_MIGHT_EXIST', default_value)
  47.  
  48. [group1]
  49. env=qa
  50.  
  51. [urlConfig]
  52. address=http://something
  53.  
  54. [dbConfig]
  55. user=test
  56. pass=test
  57.  
  58. from testconfig import config
  59.  
  60. print(config['dbConfig']['user'])
  61.  
  62. args = sys.argv[1:]
  63. sys.argv = sys.argv[0:1]
  64.  
  65. from testconfig import config
  66. def test_os_specific_code():
  67. os_name = config['os']['type']
  68. if os_name == 'nt':
  69. pass # some nt specific tests
  70. else:
  71. pass # tests for any other os
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement