I have a file with the following lines:
suite = LazySuite(all_tests)
run(suite=suite, argv=['','-c', 'nose.cfg'] )
And I have this nose config file:
[nosetests]
stop=1
with-xunit=1
xunit-file=test.xml
And when I run the testsuite, the following message is showed:
Usage: TestSuite1.py [options]
TestSuite1.py: error: Error reading config file 'nose.cfg': no such option 'with-xunit'
Process finished with exit code 2
I don't know what is happening, because if I execute the xunit plugin in the cmd directly as argument, the script is executed without problems.
Any suggestion?
I found the problem.
I was defining the configure in the following lines:
c = Config()
cf = c.configure(argv=['','-c', 'nose.cfg'])
:)
Related
I am trying to get remoteconfig working, following this guide:
https://pypi.org/project/remoteconfig/
As a control, I have this code that works:
config.read('./config.ini')
for section in config:
print(section)
When I put the same config file in a remote Gitlab, this code does not work:
from remoteconfig import config
config.read('https://myorg.org/path/repo/~/blob/app/config.ini')
for section in config:
print(section)
What could I be doing wrong here? The error msg I am getting is:
configParser.MissingSectionHeaderError: File contains no section headers
So it seems like it's reaching the file path (network/connectivity OK), but not liking what's in that file or possibly the file format? The same exact file works with localconfig.
For now I am going to use the 'gitlab' pip module and simply consume the API for the file (with private_token:
f = project.files.get(file_path='path/file', ref='master'
I am trying to update my Selenium Grid Hub capable tests to run via the nose tests framework.
Currently, without nosetests, if I wanted to start a process and have it run against a specific node I'd add this type of code in the SelRunner.py file
p1 = subprocess.Popen('python Tst_Ayusa_Nmo.py 5564 WINDOWS chrome')
This would then pass the system parameters of 5564 WINDOWS chrome into my test file, and it will know which Grid node it should be executing.
#execute test on this node: 5564 WINDOWS chrome
def setUp(self):
if len(sys.argv) > 1:
args = sys.argv
port = args[1]
platform = args[2]
browser = args[3]
Now I've looked at various posts here about nose, but I am not quite sure how I can accomplish the same thing below:
if __name__ == '__main__':
argv = ['--with-xunit', 'Tst_Ayusa_Nmo.py 5564']
nose.main(argv=argv)
======================================================================
ERROR: Failure: AttributeError ('module' object has no attribute 'py 5564')
----------------------------------------------------------------------
Traceback (most recent call last):
File "C:\Python27\lib\site-packages\nose\loader.py", line 402, in loadTestsFromName
module = resolve_name(addr.module)
File "C:\Python27\lib\site-packages\nose\util.py", line 321, in resolve_name
obj = getattr(obj, part)
AttributeError: 'module' object has no attribute 'py 5564'
----------------------------------------------------------------------
Ran 1 test in 0.001s
FAILED (errors=1)
Thanks so much as always!
P.S. I am open to other methods of passing in the node configuration besides the command line.
I use TestConfig plugin. So I launch nose tests like the following:
nose.run(argv=['nosetests','-v','-s','--with-xunit','--tc-file','./configFile'],
plugins=[TestConfig(),Capture(),Xunit()])
and inside test I do
from testconfig import config
import sys
class testModule_1:
def test_M1_1(self):
print 'Module 1 Test 1 Config: ' + config['rc_configuration']['command']
And example of my config file:
[TEST_CONFIG]
xunitFile = firefoxTests.xml
[rc_configuration]
command = GoogleChrome
'
i have basic python agi code with pyst lib as:
extensions.conf
[from-internal]
exten => _.,1,answer()
exten => _.,2,AGI(test.py)
i have test.py in /var/lib/asterisk/agi-bin as
#!/usr/bin/python
import sys
import os
from agi import AGI
def test_call(agi = None,text = ""):
agi.say_alpha(text, "#")
agi.hangup()
if __name__ == "__main__":
text = 'abcdefr'
agi = AGI()
test_call(agi,text)
and i have one file agi.py which is get from pyst lib.
when i try to call to this agi i get this issue
Executing [123#from-internal:1] Answer("SIP/12345-00000016", "") in new stack
[Mar 14 00:01:29] NOTICE[2790]: res_rtp_asterisk.c:2358 ast_rtp_read: Unknown RTP codec 126 received from '169.254.38.82:20338'
-- Executing [123#from-internal:2] AGI("SIP/12345-00000016", "test.py") in new stack
-- Launched AGI Script /var/lib/asterisk/agi-bin/test.py
test.py: Failed to execute '/var/lib/asterisk/agi-bin/test.py': No such file or directory
-- Auto fallthrough, channel 'SIP/12345-00000016' status is 'UNKNOWN'
-- Executing [h#from-internal:1] Hangup("SIP/12345-00000016", "") in new stack
== Spawn extension (from-internal, h, 1) exited non-zero on 'SIP/12345-00000016'
i see that i have this file in /var/lib/asterisk/agi-bin which 777 permission.
Please suggest to get this basic script work.
thank all in advance
There can be 2 reason for such error:
no file /var/lib/asterisk/agi-bin/test.py in that location or it not accessable by asterisk for some reason - linux general permission issue.
file /var/lib/asterisk/agi-bin/test.py, but no some libraries(python give same error). This one is more likly. Try execute script manual from asterisk user and see what it say.
Recomendation: Use FastAGI instead of AGI.
I'm trying to create a complex mercurial commit hook in python. I want to also be allowed to pass parameters using OptionParser. Here is the gist of what I have so far:
.hg/hgrc config:
[hooks]
commit = python:/mydir/pythonFile.py:main
# using python:/mydir/pythonFile.py doesn't work for some reason either
pythonFile.py:
def main(ui, repo, **kwargs):
from optparse import OptionParser
parser = OptionParser()
parser.add_option('--test-dir', action='store', type="string",
dest='test_dir', default='otherdir/',
help='help info')
(options, args) = parser.parse_args()
# do some stuff here
someFunc(options.test_dir)
if __name__ == '__main__':
import sys
main(sys.argv[0], sys.argv[1], sys.argv[2:])
When I run hg commit -m 'message' I get an error: "Usage: hg [options] hg: error: no such option: -m". When I try hg commit --test-dir '/somedir' I get an error: "hg commit: option --test-dir not recognized".
Lastly I tried specifying commit = python:/mydir/pythonFile.py:main --test-dir '/somedir' in the hgrc config and I got this error: "AttributeError: 'module' object has no attribute 'main --test-dir '/somedir''"
Thank you for your help.
I think your problem may be in trying to import something that isn't part of the python packaged with mercurial.
If what you need is to pass additional information to the hook such that you can configure it differently for different repos/branches etc, you could use
param_value= ui.config('ini_section', 'param_key', default='', untrusted=False)
where ini_section is the bit in [] in the mercurial.ini / .hgrc file and param_key is the name of the entry
so something like
[my_hook_params]
test-dir=/somedir
then use
test_dir = ui.config('my_hook_params', 'test-dir', default='otherdir/', untrusted=False)
The following code:
gb = self.request.form['groupby']
typ = self.request.form['type']
tbl = self.request.form['table']
primary = self.request.form.get('primary', None)
if primary is not None:
create = False
else:
create = True
mdb = tempfile.NamedTemporaryFile()
mdb.write(self.request.form['mdb'].read())
mdb.seek(0)
csv = tempfile.TemporaryFile()
conversion = subprocess.Popen(("/Users/jondoe/development/mdb-export", mdb.name, tbl,),stdout=csv)
Causes the this error when calling the last line i.e. 'conversion =' in OS X.
Traceback (innermost last):
Module ZPublisher.Publish, line 119, in publish
Module ZPublisher.mapply, line 88, in mapply
Module ZPublisher.Publish, line 42, in call_object
Module circulartriangle.mdbtoat.mdb, line 62, in __call__
Module subprocess, line 543, in __init__
Module subprocess, line 975, in _execute_child
OSError: [Errno 13] Permission denied
I've tried chmod 777 /Users/jondoe/development/mdb-export - what else might be required?
Assuming that permissions on parent folders are correct (i.e. all parent folders should have +x permission), try adding:
shell=True
to the Popen command such as:
subprocess.Popen(("/Users/jondoe/development/mdb-export", mdb.name, tbl,), stdout=csv, shell=True)
It seems the 'Permissions denied error' was orginally coming from Popen trying to execute mdb-export from the wrong location (and to compound things, with the wrong permissions).
If mdbtools is installed, the following works fine and inherits the correct permissions without the need for sudo etc.
subprocess.Popen(("mdb-export", mdb.name, tbl,),stdout=csv)
(Worth noting, I got myself into a muddle for a while, having forgotten that Popen is for opening executables, not folders or non-exectable files in folders)
Thanks for all your responses, they all made for interesting reading regardless :)
Can you feed "sudo" to subprocess? See this SO thread.
#Jon Hadley, from the interpreter:
>>> import subprocess
>>> p = subprocess.call(['sudo','/usr/bin/env'])
PASSWORD:
[snip]
USER=root
USERNAME=root
SUDO_COMMAND=/usr/bin/env
SUDO_USER=telliott99
SUDO_UID=501
SUDO_GID=20
From Terminal on OS X, I have to do sudo when I run the script:
$ sudo python test.py
then this (in test.py) gives the same output as before:
import subprocess
p = subprocess.Popen('/usr/bin/env')
Getting subprocess to directly handle the authentication from a script is probably not a good idea, since it hides the privilege escalation. But you could look at pexpect and this SO answer.
You also need to ensure read and execute permissions for the user running that code on the directories up the chain - /Users, /Users/jondoe and /Users/jondoe/development.