Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import nose, sys
- def test():
- # do something with the command line arguments
- print sys.argv
- if __name__ == '__main__':
- nose.runmodule()
- $ python test.py arg
- E
- ======================================================================
- ERROR: Failure: ImportError (No module named arg)
- ----------------------------------------------------------------------
- Traceback (most recent call last):
- 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
- module = resolve_name(addr.module)
- 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
- module = __import__('.'.join(parts_copy))
- ImportError: No module named arg
- ----------------------------------------------------------------------
- Ran 1 test in 0.001s
- FAILED (errors=1)
- import sys
- class test_something(object):
- def setUp(self):
- sys.argv[1] = 'arg'
- del sys.argv[2] # remember that -s is in sys.argv[2], see below
- def test_method(self):
- print sys.argv
- [~] nosetests test_something.py -s
- ['/usr/local/bin/nosetests', 'arg']
- .
- ----------------------------------------------------------------------
- Ran 1 test in 0.001s
- OK
- import os
- print os.getenv('KEY_THAT_MIGHT_EXIST', default_value)
- [group1]
- env=qa
- [urlConfig]
- address=http://something
- [dbConfig]
- user=test
- pass=test
- from testconfig import config
- print(config['dbConfig']['user'])
- args = sys.argv[1:]
- sys.argv = sys.argv[0:1]
- from testconfig import config
- def test_os_specific_code():
- os_name = config['os']['type']
- if os_name == 'nt':
- pass # some nt specific tests
- else:
- pass # tests for any other os
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement