From anton7811 at gmail.com Tue Feb 5 15:51:23 2013 From: anton7811 at gmail.com (Anton P) Date: Tue, 5 Feb 2013 16:51:23 +0200 Subject: [pytest-dev] pytest_runtest_call hook skipped in strange manner Message-ID: Hi All, I'm faced with very strange issue with runtest_call hook. I've create plugin with such hook and it's working good unless you have the following code in the test case: assert env.switch[1].type == "real" If you change at least on sign in this assertion (e.g. != "real" or == "unreal") the issue cannot be reproduced and hook is performed correctly. Could anybody explain me what is going with this test case? Thank you in advance! -Anton Here the code: $ tree . ??? conftest.py ??? pytest_fake.py ??? test_temp.py *1. conftest.py* #! /usr/bin/env python pytest_plugins = ["pytest_fake", ] def pytest_runtest_call(item): print "\nconftest runtest call" def pytest_runtest_teardown(item, nextitem): print "\nconftest runtest teardown" *2. pytest_fake.py* #!/usr/bin/env python import pytest def pytest_addoption(parser): group = parser.getgroup("fake", "plugin fake") group.addoption("--fake", action="store_true", dest="fake", default=False, help="Enable fake plugin. %default by default.") def pytest_configure(config): if config.option.fake: config.pluginmanager.register(Fake(config.option), "_fake") def pytest_unconfigure(config): fake = getattr(config, "_fake", None) if fake: del config._fake config.pluginmanager.unregister(fake) class Fake(object): def __init__(self, opts): pass @pytest.mark.trylast def pytest_runtest_call(self, item): print "runtest_call - OK" @pytest.mark.tryfirst def pytest_runtest_teardown(self, item, nextitem): print "runtest_teardown" *3. test_temp.py* #! /usr/bin/env python class A: pass class B: def __init__(self): self.switch = {} self.switch[1] = A() self.switch[1].type = "unreal" class TestTemp(object): def test_tmp_01(self): var = B() assert var.switch[1].type == "real" def test_tmp_02(self): env1 = B() assert env1.switch[1].type != "real" *Execution log:* I'm expecting that message "runtest_call - OK" will appear before the first case. $ py.test -s -v --fake test_temp.py ================================================= test session starts ================================================= platform linux2 -- Python 2.7.3 -- pytest-2.3.4 -- /usr/bin/python collected 2 items test_temp.py:13: TestTemp.test_tmp_01 conftest runtest call FAILEDruntest_teardown conftest runtest teardown test_temp.py:17: TestTemp.test_tmp_02 conftest runtest call runtest_call - OK PASSEDruntest_teardown conftest runtest teardown ====================================================== FAILURES ======================================================= ________________________________________________ TestTemp.test_tmp_01 _________________________________________________ self = def test_tmp_01(self): var = B() > assert var.switch[1].type == "real" E assert 'unreal' == 'real' E - unreal E ? -- E + real self = var = test_temp.py:15: AssertionError =============================================== slowest test durations ================================================ 0.00s call test_temp.py::TestTemp::test_tmp_01 0.00s setup test_temp.py::TestTemp::test_tmp_01 0.00s teardown test_temp.py::TestTemp::test_tmp_01 0.00s call test_temp.py::TestTemp::test_tmp_02 0.00s setup test_temp.py::TestTemp::test_tmp_02 0.00s teardown test_temp.py::TestTemp::test_tmp_02 ========================================= 1 failed, 1 passed in 0.02 seconds ========================================== -------------- next part -------------- An HTML attachment was scrubbed... URL: From anton7811 at gmail.com Wed Feb 6 12:56:27 2013 From: anton7811 at gmail.com (Anton P) Date: Wed, 6 Feb 2013 13:56:27 +0200 Subject: [pytest-dev] pytest_runtest_call hook skipped in strange manner In-Reply-To: References: Message-ID: Sorry for confusing, but it looks like runtest_call hook defined in plugin is always skiped in case test is failed. I've tried to add there some output to file to be sure that there is no issue with pytest stdout capturing. This issue creates a problem for me. Because plugin does some stuff before test and try to verify that stuff is good after test finished. But if tc could be failed (does py.test can predict the result?!) runtest_call hook is skipped but runtest_teardown hook is run as usual. Therefore I get double error: tc failed, teardown failed. If nobody has time to check this, than please point me where I can check the issue by myself. Why the hook could be skipped? Ubuntu Linux 12.04 -- Python 2.7.3 -- pytest-2.3.4 Thank you in advance! -Anton On Tue, Feb 5, 2013 at 4:51 PM, Anton P wrote: > Hi All, > > I'm faced with very strange issue with runtest_call hook. > I've create plugin with such hook and it's working good unless you have > the following code in the test case: > assert env.switch[1].type == "real" > If you change at least on sign in this assertion (e.g. != "real" or == > "unreal") the issue cannot be reproduced and hook is performed correctly. > > Could anybody explain me what is going with this test case? > > Thank you in advance! > -Anton > > > Here the code: > > > $ tree > . > ??? conftest.py > ??? pytest_fake.py > ??? test_temp.py > > *1. conftest.py* > #! /usr/bin/env python > > pytest_plugins = ["pytest_fake", ] > > def pytest_runtest_call(item): > print "\nconftest runtest call" > > def pytest_runtest_teardown(item, nextitem): > print "\nconftest runtest teardown" > > *2. pytest_fake.py* > #!/usr/bin/env python > > import pytest > > > def pytest_addoption(parser): > group = parser.getgroup("fake", "plugin fake") > group.addoption("--fake", action="store_true", dest="fake", > default=False, > help="Enable fake plugin. %default by default.") > > > def pytest_configure(config): > if config.option.fake: > config.pluginmanager.register(Fake(config.option), "_fake") > > > def pytest_unconfigure(config): > fake = getattr(config, "_fake", None) > if fake: > del config._fake > config.pluginmanager.unregister(fake) > > > class Fake(object): > > def __init__(self, opts): > pass > > @pytest.mark.trylast > def pytest_runtest_call(self, item): > print "runtest_call - OK" > > @pytest.mark.tryfirst > def pytest_runtest_teardown(self, item, nextitem): > print "runtest_teardown" > > *3. test_temp.py* > #! /usr/bin/env python > > class A: > pass > > class B: > def __init__(self): > self.switch = {} > self.switch[1] = A() > self.switch[1].type = "unreal" > > class TestTemp(object): > def test_tmp_01(self): > var = B() > assert var.switch[1].type == "real" > > def test_tmp_02(self): > env1 = B() > assert env1.switch[1].type != "real" > > > > *Execution log:* > > I'm expecting that message "runtest_call - OK" will appear before the > first case. > > $ py.test -s -v --fake test_temp.py > ================================================= test session starts > ================================================= > platform linux2 -- Python 2.7.3 -- pytest-2.3.4 -- /usr/bin/python > collected 2 items > > test_temp.py:13: TestTemp.test_tmp_01 > conftest runtest call > FAILEDruntest_teardown > > conftest runtest teardown > > test_temp.py:17: TestTemp.test_tmp_02 > conftest runtest call > runtest_call - OK > PASSEDruntest_teardown > > conftest runtest teardown > > > ====================================================== FAILURES > ======================================================= > ________________________________________________ TestTemp.test_tmp_01 > _________________________________________________ > > self = > > def test_tmp_01(self): > var = B() > > assert var.switch[1].type == "real" > E assert 'unreal' == 'real' > E - unreal > E ? -- > E + real > > self = > var = > > test_temp.py:15: AssertionError > =============================================== slowest test durations > ================================================ > 0.00s call test_temp.py::TestTemp::test_tmp_01 > 0.00s setup test_temp.py::TestTemp::test_tmp_01 > 0.00s teardown test_temp.py::TestTemp::test_tmp_01 > 0.00s call test_temp.py::TestTemp::test_tmp_02 > 0.00s setup test_temp.py::TestTemp::test_tmp_02 > 0.00s teardown test_temp.py::TestTemp::test_tmp_02 > ========================================= 1 failed, 1 passed in 0.02 > seconds ========================================== > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From holger at merlinux.eu Wed Feb 6 14:00:49 2013 From: holger at merlinux.eu (holger krekel) Date: Wed, 6 Feb 2013 13:00:49 +0000 Subject: [pytest-dev] pytest_runtest_call hook skipped in strange manner In-Reply-To: References: Message-ID: <20130206130049.GB3520@merlinux.eu> Hi Anton, pytest_runtest_call is responsible for executing the test. An exception will escalate, so not all plugin hook impls might execute in the case of a failing test. If you use @pytest.mark.tryfirst before the pytest_runtest_call you should be able to avoid the problem - your hook will run. HTH, holger On Wed, Feb 06, 2013 at 13:56 +0200, Anton P wrote: > Sorry for confusing, but it looks like runtest_call hook defined in plugin > is always skiped in case test is failed. > I've tried to add there some output to file to be sure that there is no > issue with pytest stdout capturing. > This issue creates a problem for me. Because plugin does some stuff before > test and try to verify that stuff is good after test finished. But if tc > could be failed (does py.test can predict the result?!) runtest_call hook > is skipped but runtest_teardown hook is run as usual. Therefore I get > double error: tc failed, teardown failed. > > If nobody has time to check this, than please point me where I can check > the issue by myself. Why the hook could be skipped? > > Ubuntu Linux 12.04 -- Python 2.7.3 -- pytest-2.3.4 > > Thank you in advance! > -Anton > > > On Tue, Feb 5, 2013 at 4:51 PM, Anton P wrote: > > > Hi All, > > > > I'm faced with very strange issue with runtest_call hook. > > I've create plugin with such hook and it's working good unless you have > > the following code in the test case: > > assert env.switch[1].type == "real" > > If you change at least on sign in this assertion (e.g. != "real" or == > > "unreal") the issue cannot be reproduced and hook is performed correctly. > > > > Could anybody explain me what is going with this test case? > > > > Thank you in advance! > > -Anton > > > > > > Here the code: > > > > > > $ tree > > . > > ??? conftest.py > > ??? pytest_fake.py > > ??? test_temp.py > > > > *1. conftest.py* > > #! /usr/bin/env python > > > > pytest_plugins = ["pytest_fake", ] > > > > def pytest_runtest_call(item): > > print "\nconftest runtest call" > > > > def pytest_runtest_teardown(item, nextitem): > > print "\nconftest runtest teardown" > > > > *2. pytest_fake.py* > > #!/usr/bin/env python > > > > import pytest > > > > > > def pytest_addoption(parser): > > group = parser.getgroup("fake", "plugin fake") > > group.addoption("--fake", action="store_true", dest="fake", > > default=False, > > help="Enable fake plugin. %default by default.") > > > > > > def pytest_configure(config): > > if config.option.fake: > > config.pluginmanager.register(Fake(config.option), "_fake") > > > > > > def pytest_unconfigure(config): > > fake = getattr(config, "_fake", None) > > if fake: > > del config._fake > > config.pluginmanager.unregister(fake) > > > > > > class Fake(object): > > > > def __init__(self, opts): > > pass > > > > @pytest.mark.trylast > > def pytest_runtest_call(self, item): > > print "runtest_call - OK" > > > > @pytest.mark.tryfirst > > def pytest_runtest_teardown(self, item, nextitem): > > print "runtest_teardown" > > > > *3. test_temp.py* > > #! /usr/bin/env python > > > > class A: > > pass > > > > class B: > > def __init__(self): > > self.switch = {} > > self.switch[1] = A() > > self.switch[1].type = "unreal" > > > > class TestTemp(object): > > def test_tmp_01(self): > > var = B() > > assert var.switch[1].type == "real" > > > > def test_tmp_02(self): > > env1 = B() > > assert env1.switch[1].type != "real" > > > > > > > > *Execution log:* > > > > I'm expecting that message "runtest_call - OK" will appear before the > > first case. > > > > $ py.test -s -v --fake test_temp.py > > ================================================= test session starts > > ================================================= > > platform linux2 -- Python 2.7.3 -- pytest-2.3.4 -- /usr/bin/python > > collected 2 items > > > > test_temp.py:13: TestTemp.test_tmp_01 > > conftest runtest call > > FAILEDruntest_teardown > > > > conftest runtest teardown > > > > test_temp.py:17: TestTemp.test_tmp_02 > > conftest runtest call > > runtest_call - OK > > PASSEDruntest_teardown > > > > conftest runtest teardown > > > > > > ====================================================== FAILURES > > ======================================================= > > ________________________________________________ TestTemp.test_tmp_01 > > _________________________________________________ > > > > self = > > > > def test_tmp_01(self): > > var = B() > > > assert var.switch[1].type == "real" > > E assert 'unreal' == 'real' > > E - unreal > > E ? -- > > E + real > > > > self = > > var = > > > > test_temp.py:15: AssertionError > > =============================================== slowest test durations > > ================================================ > > 0.00s call test_temp.py::TestTemp::test_tmp_01 > > 0.00s setup test_temp.py::TestTemp::test_tmp_01 > > 0.00s teardown test_temp.py::TestTemp::test_tmp_01 > > 0.00s call test_temp.py::TestTemp::test_tmp_02 > > 0.00s setup test_temp.py::TestTemp::test_tmp_02 > > 0.00s teardown test_temp.py::TestTemp::test_tmp_02 > > ========================================= 1 failed, 1 passed in 0.02 > > seconds ========================================== > > > > > _______________________________________________ > Pytest-dev mailing list > Pytest-dev at python.org > http://mail.python.org/mailman/listinfo/pytest-dev From xurongzhong at gmail.com Mon Feb 25 11:23:36 2013 From: xurongzhong at gmail.com (=?GB2312?B?0OzI2dbQ?=) Date: Mon, 25 Feb 2013 18:23:36 +0800 Subject: [pytest-dev] =?windows-1252?q?Could_I_print_=93current_line_and_s?= =?windows-1252?q?tatement=94_to_stdout_in_pytest=3F?= Message-ID: Could I print "current line and statement" to stdout in pytest? I want to modify pytest files to achieve the following: line 9: snmp_get(node1.1) line 10: snmp_set(nod1.2) Anyone can tell me where to modify? Thanks! -------------- next part -------------- An HTML attachment was scrubbed... URL: From Ronny.Pfannschmidt at gmx.de Mon Feb 25 11:34:06 2013 From: Ronny.Pfannschmidt at gmx.de (Ronny Pfannschmidt) Date: Mon, 25 Feb 2013 11:34:06 +0100 Subject: [pytest-dev] =?utf-8?q?Could_I_print_=E2=80=9Ccurrent_line_and_st?= =?utf-8?q?atement=E2=80=9D_to_stdout_in_pytest=3F?= In-Reply-To: References: Message-ID: <512B3E1E.6050003@gmx.de> in what context ? On 02/25/2013 11:23 AM, ??? wrote: > Could I print "current line and statement" to |stdout| in |pytest|? I > want to modify |pytest| files to achieve the following: > > |line9: snmp_get(node1.1) > line10: snmp_set(nod1.2)| > > Anyone can tell me where to modify? > > Thanks! > > > > _______________________________________________ > Pytest-dev mailing list > Pytest-dev at python.org > http://mail.python.org/mailman/listinfo/pytest-dev From xurongzhong at gmail.com Mon Feb 25 11:38:45 2013 From: xurongzhong at gmail.com (=?GB2312?B?0OzI2dbQ?=) Date: Mon, 25 Feb 2013 18:38:45 +0800 Subject: [pytest-dev] =?windows-1252?q?Could_I_print_=93current_line_and_s?= =?windows-1252?q?tatement=94_to_stdout_in_pytest=3F?= In-Reply-To: <512B3E1E.6050003@gmx.de> References: <512B3E1E.6050003@gmx.de> Message-ID: In test steps: I want to py.test to print line number and statment when excecute step. Example, put "line 11: snmp_set(node)" when excecut "snmp_set(node1)", Is it possible? @pytest.mark.webtest @pytest.mark.high def test_send_http(): mylogger.info('\nInside Setup') def test_something_quick(): snmp_set(node1) print "\n test_something_quick" def test_another(): pass 2013/2/25 Ronny Pfannschmidt > in what context ? > > On 02/25/2013 11:23 AM, ??? wrote: > >> Could I print "current line and statement" to |stdout| in |pytest|? I >> >> want to modify |pytest| files to achieve the following: >> >> |line9: snmp_get(node1.1) >> line10: snmp_set(nod1.2)| >> >> >> Anyone can tell me where to modify? >> >> Thanks! >> >> >> >> ______________________________**_________________ >> Pytest-dev mailing list >> Pytest-dev at python.org >> http://mail.python.org/**mailman/listinfo/pytest-dev >> > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From Ronny.Pfannschmidt at gmx.de Mon Feb 25 11:45:43 2013 From: Ronny.Pfannschmidt at gmx.de (Ronny Pfannschmidt) Date: Mon, 25 Feb 2013 11:45:43 +0100 Subject: [pytest-dev] =?gb2312?b?Q291bGQgSSBwcmludCChsGN1cnJlbnQgbGluZSBh?= =?gb2312?b?bmQgc3RhdGVtZW50obEgdG8gc3Rkb3V0IGluIHB5dGVzdD8=?= In-Reply-To: References: <512B3E1E.6050003@gmx.de> Message-ID: <512B40D7.9050009@gmx.de> so am i asuming it correct that you want *python* to print line numbers and statements as it executes your code, since py.test tests executing are just python code running you can do that by implementing a own trace function (sys.settrace) and hooking into pytest_runtest_call for example On 02/25/2013 11:38 AM, ??? wrote: > In test steps: > I want to py.test to print line number and statment when excecute step. > Example, put "line 11: snmp_set(node)" when excecut "snmp_set(node1)", > Is it possible? > > @pytest.mark.webtest > @pytest.mark.high > def test_send_http(): > mylogger.info ('\nInside Setup') > def test_something_quick(): > snmp_set(node1) > print "\n test_something_quick" > def test_another(): > pass > > 2013/2/25 Ronny Pfannschmidt > > > in what context ? > > On 02/25/2013 11:23 AM, ??? wrote: > > Could I print "current line and statement" to |stdout| in > |pytest|? I > > want to modify |pytest| files to achieve the following: > > |line9: snmp_get(node1.1) > line10: snmp_set(nod1.2)| > > > Anyone can tell me where to modify? > > Thanks! > > > > _________________________________________________ > Pytest-dev mailing list > Pytest-dev at python.org > http://mail.python.org/__mailman/listinfo/pytest-dev > > > > From xurongzhong at gmail.com Tue Feb 26 07:41:27 2013 From: xurongzhong at gmail.com (=?GB2312?B?0OzI2dbQ?=) Date: Tue, 26 Feb 2013 14:41:27 +0800 Subject: [pytest-dev] =?windows-1252?q?Could_I_print_=93current_line_and_s?= =?windows-1252?q?tatement=94_to_stdout_in_pytest=3F?= In-Reply-To: <512B40D7.9050009@gmx.de> References: <512B3E1E.6050003@gmx.de> <512B40D7.9050009@gmx.de> Message-ID: Hi Ronny: Thank you very much! I modify code according to your advice and everything is ok! #! /usr/bin/env python #coding=utf-8 import sys import os import pytest def trace_calls(frame, event, arg): if event != 'call': return co = frame.f_code func_name = co.co_name if func_name == 'write': # Ignore write() calls from print statements return func_line_no = frame.f_lineno func_filename = co.co_filename if 'robot_' not in func_filename: return caller = frame.f_back caller_line_no = caller.f_lineno caller_filename = caller.f_code.co_filename print '\n{0} : {1} --{2}'.format(func_filename.split(os.sep)[-1], caller_line_no, func_name) return sys.settrace(trace_calls) @pytest.mark.webtest @pytest.mark.high def test_send_http(): print('\nInside Setup') def test_something_quick(): assert 1 == 1 print "\n test_something_quick" def test_another(): pass 2013/2/25 Ronny Pfannschmidt > so am i asuming it correct that you want *python* to print line numbers > and statements as it executes your code, since py.test tests executing > are just python code running > > you can do that by implementing a own trace function (sys.settrace) and > hooking into pytest_runtest_call for example > > On 02/25/2013 11:38 AM, ??? wrote: > > In test steps: > > I want to py.test to print line number and statment when excecute step. > > Example, put "line 11: snmp_set(node)" when excecut "snmp_set(node1)", > > Is it possible? > > > > @pytest.mark.webtest > > @pytest.mark.high > > def test_send_http(): > > mylogger.info ('\nInside Setup') > > def test_something_quick(): > > snmp_set(node1) > > print "\n test_something_quick" > > def test_another(): > > pass > > > > 2013/2/25 Ronny Pfannschmidt > > > > > > in what context ? > > > > On 02/25/2013 11:23 AM, ??? wrote: > > > > Could I print "current line and statement" to |stdout| in > > |pytest|? I > > > > want to modify |pytest| files to achieve the following: > > > > |line9: snmp_get(node1.1) > > line10: snmp_set(nod1.2)| > > > > > > Anyone can tell me where to modify? > > > > Thanks! > > > > > > > > _________________________________________________ > > Pytest-dev mailing list > > Pytest-dev at python.org > > http://mail.python.org/__mailman/listinfo/pytest-dev > > > > > > > > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From xurongzhong at gmail.com Tue Feb 26 11:53:49 2013 From: xurongzhong at gmail.com (=?GB2312?B?0OzI2dbQ?=) Date: Tue, 26 Feb 2013 18:53:49 +0800 Subject: [pytest-dev] Could we disable stack info in pytest? Message-ID: Hi, all: when a fail occur, pytest print a lot of error info. Could we disable stack info in pytest? We only need error summary info like following: _____________________________________________________________________ test_ntp ______________________________________________________________________ @pytest.mark.webtest @pytest.mark.high def test_ntp(): host = snmp.Snmp() host.snmp_connect(hostname='172.23.191.53', version=2, community='private') for ip in ('33.33.1.2', '172.22.1.8'): host.snmp_set_check('ntpPrimaryServer.0=' + ip) for ntpClientEnabled in ('true', 'false'): > host.snmp_set_check('ntpClientEnabled.1=' + ntpClientEnabled) robot_test.py:15: Thanks! Andrew Following is code and run result: # vi robot_test.py #! /usr/bin/env python #coding=utf-8 from adva_configure import * import snmp @pytest.mark.webtest @pytest.mark.high def test_ntp(): host = snmp.Snmp() host.snmp_connect(hostname='172.23.191.53', version=2, community='private') for ip in ('33.33.1.2', '172.22.1.8'): host.snmp_set_check('ntpPrimaryServer.0=' + ip) for ntpClientEnabled in ('true', 'false'): host.snmp_set_check('ntpClientEnabled.1=' + ntpClientEnabled) def test_something_quick(): assert 1 == 1 print "\n test_something_quick" def test_another(): pass #pytest.main("robot_test.py -sv") [root at SZX-SRV-AUTOMATION python]# py.test -sv robot_test.py ================================================================ test session starts ================================================================ platform linux2 -- Python 2.6.6 -- pytest-2.3.4 -- /usr/bin/python collected 3 items robot_test.py:7: test_ntp ==============================Test Case: test_ntp python.py:152 robot_test.py:7 test_ntp robot_test.py:11 snmp.py:538 snmp_connect snmp_connect(172.23.191.53, 2, 161, 30000000, 0, private) robot_test.py:13 snmp.py:875 snmp_set_check snmp_set_check(('ntpPrimaryServer.0=33.33.1.2',)) snmp.py:913 snmp.py:808 snmp_set snmp_set(('ntpPrimaryServer.0=33.33.1.2',)) snmp.py:914 snmp.py:683 snmp_get snmp_get(('ntpPrimaryServer.0=33.33.1.2',)) robot_test.py:13 snmp.py:875 snmp_set_check snmp_set_check(('ntpPrimaryServer.0=172.22.1.8',)) snmp.py:913 snmp.py:808 snmp_set snmp_set(('ntpPrimaryServer.0=172.22.1.8',)) snmp.py:914 snmp.py:683 snmp_get snmp_get(('ntpPrimaryServer.0=172.22.1.8',)) robot_test.py:15 snmp.py:875 snmp_set_check snmp_set_check(('ntpClientEnabled.1=true',)) snmp.py:913 snmp.py:808 snmp_set snmp_set(('ntpClientEnabled.1=true',)) snmp.py:857 snmp.py:683 snmp_get snmp_get(('-s', 'lastSetErrorInformation.0')) FAILED ==============================End of Test Case robot_test.py:18: test_something_quick ==============================Test Case: test_something_quick python.py:152 robot_test.py:18 test_something_quick test_something_quick PASSED ==============================End of Test Case robot_test.py:23: test_another ==============================Test Case: test_another python.py:152 robot_test.py:23 test_another PASSED ==============================End of Test Case ===================================================================== FAILURES ====================================================================== _____________________________________________________________________ test_ntp ______________________________________________________________________ @pytest.mark.webtest @pytest.mark.high def test_ntp(): host = snmp.Snmp() host.snmp_connect(hostname='172.23.191.53', version=2, community='private') for ip in ('33.33.1.2', '172.22.1.8'): host.snmp_set_check('ntpPrimaryServer.0=' + ip) for ntpClientEnabled in ('true', 'false'): > host.snmp_set_check('ntpClientEnabled.1=' + ntpClientEnabled) robot_test.py:15: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , args = ('ntpClientEnabled.1=true',), var_list = [] var_list_txt = [{'expect_value': 'true', 'index': '1', 'name': 'ntpClientEnabled.1', 'noid': '.1.3.6.1.4.1.2544.1.12.2.1.10.1', ...}] @classmethod def snmp_set_check(self, *args): ''' *Set and check a list of soids and values. * --Without '-N' (negative) tag, for example snmp_set_check('ecpaControlDuration.1.1.1.1=20'), set the ecpaControlDuration.1.1.1.1 to 20 and check result. Test fail - a, errors from Node: lastSetError - b, timeout and other errors from netsnmp. - c, Node and index Error etc from adva python snmp library. - d, value not equal --With '-N' (negative) tag, for example snmp_set('ecpaControlDuration.1.1.1.1=0, '-N'), set the ecpaControlDuration.1.1.1.1 to 20 and Test fails if: - a, set ok - b, Node Error etc(index not included) from adva python snmp library. - c, timeout and other errors from netsnmp. | *Fixed argument* | *type* | *description* | | *args | string | one or more string like ecpaControlDuration.1.1.1.1=\ 0, -N, ntpClientEnabled.0=false -c true | | *optional argument* | *type* | *description* | | -N | bool switch | With this tag do Negative check. \ Without this tag do normal check. | | *Return type* | *Example* | | None | None | *--Robot Example* | snmp_set_check | ntpClientEnabled.0=false -c true | \ ecpaControlTestType.1.1.24.1=createAndGo | -N | | snmp_set_check | ecpaControlTestType.1.1.24.1=createAndGo' | ''' print colors.yellow('\t\tsnmp_set_check({0})'.format(args)) var_list, var_list_txt = _convert_args_to_list(args, return_txt=True) > snmp_result = Snmp.snmp_set(*args) /opt/adva/snmp.py:913: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , args = ('ntpClientEnabled.1=true',), var_list = [] var_list_txt = [{'expect_value': 'true', 'index': '1', 'name': 'ntpClientEnabled.1', 'noid': '.1.3.6.1.4.1.2544.1.12.2.1.10.1', ...}] snmp_result = 0 @classmethod def snmp_set(self, *args): ''' --Set a list of soids and values. -Without '-N' (negative) tag, for example snmp_set('ecpaControlDuration.1.1.1.1=20'), set the ecpaControlDuration.1.1.1.1 to 20 . Test fail if: - a, errors from Node: lastSetError - b, timeout and other errors from netsnmp. - c, Node and index Error etc from adva python snmp library. -With '-N' (negative) tag, for example snmp_set('ecpaControlDuration.1.1.1.1=0, '-N'), set the ecpaControlDuration.1.1.1.1 to 20 and Test fails if: - a, set ok - b, Node Error etc(index not included) from adva python snmp library. - c, timeout and other errors from netsnmp. | *Fixed argument* | *type* | *description* | | *args | string | one or more string like ecpaControlDuration.1.1.1.1=\ 0, -N | | *optional argument* | *type* | *description* | | -N | bool switch | With this tag do Negative check. \ Without this tag do normal check. | | *Return type* | *Example* | | None | None | *--Robot Example* | snmp set | ecpaControlDuration.1.1.1.1=0 | -N | | snmp set | ecpaControlDuration.1.1.1.1=20 | ''' print colors.yellow('\t\tsnmp_set({0})'.format(args)) var_list, var_list_txt = _convert_args_to_list(args, return_txt=True) snmp_result = Snmp.client.set(var_list) # netsnmp python binding return 0 if set fail, return 1 if set ok # we need to convert it to the same format as snmp set. if snmp_result == 1 and Snmp.reverse: output_console_error( "SnmpSetNegativeError", str(args)) if snmp_result == 1 and (not Snmp.reverse): return if snmp_result == 0 and (not Snmp.reverse): #print colors.red('\t\t snmp_set Error') error_info = Snmp.snmp_get('-s', "lastSetErrorInformation.0") #print colors.red('\t\t lastSetErrorInformation: '), > assert 0 == 1 E assert 0 == 1 /opt/adva/snmp.py:859: AssertionError ======================================================== 1 failed, 2 passed in 2.34 seconds ======================================================== -------------- next part -------------- An HTML attachment was scrubbed... URL: From xurongzhong at gmail.com Thu Feb 28 08:46:35 2013 From: xurongzhong at gmail.com (=?GB2312?B?0OzI2dbQ?=) Date: Thu, 28 Feb 2013 15:46:35 +0800 Subject: [pytest-dev] Could we disable stack info in pytest? In-Reply-To: References: Message-ID: Hi, all: I found comment " self._outrep_summary(rep)" of file terminal.py can disable this function. However, this can not print all debug infomation. rep is a TestReport object. Maybe we need to modify it. 2013/2/26 ??? > Hi, all: > when a fail occur, pytest print a lot of error info. > Could we disable stack info in pytest? We only need error summary > info like following: > > _____________________________________________________________________ > test_ntp > ______________________________________________________________________ > > @pytest.mark.webtest > @pytest.mark.high > def test_ntp(): > host = snmp.Snmp() > host.snmp_connect(hostname='172.23.191.53', version=2, > community='private') > for ip in ('33.33.1.2', '172.22.1.8'): > host.snmp_set_check('ntpPrimaryServer.0=' + ip) > for ntpClientEnabled in ('true', 'false'): > > host.snmp_set_check('ntpClientEnabled.1=' + ntpClientEnabled) > > robot_test.py:15: > > > Thanks! > Andrew > > Following is code and run result: > > # vi robot_test.py > > #! /usr/bin/env python > #coding=utf-8 > > from adva_configure import * > import snmp > > @pytest.mark.webtest > @pytest.mark.high > def test_ntp(): > host = snmp.Snmp() > host.snmp_connect(hostname='172.23.191.53', version=2, > community='private') > for ip in ('33.33.1.2', '172.22.1.8'): > host.snmp_set_check('ntpPrimaryServer.0=' + ip) > for ntpClientEnabled in ('true', 'false'): > host.snmp_set_check('ntpClientEnabled.1=' + ntpClientEnabled) > > > def test_something_quick(): > > assert 1 == 1 > print "\n test_something_quick" > > def test_another(): > pass > > #pytest.main("robot_test.py -sv") > > > > [root at SZX-SRV-AUTOMATION python]# py.test -sv robot_test.py > ================================================================ test > session starts > ================================================================ > platform linux2 -- Python 2.6.6 -- pytest-2.3.4 -- /usr/bin/python > collected 3 items > > robot_test.py:7: test_ntp > ==============================Test Case: test_ntp > > python.py:152 robot_test.py:7 test_ntp > > robot_test.py:11 snmp.py:538 snmp_connect > snmp_connect(172.23.191.53, 2, 161, 30000000, 0, private) > > robot_test.py:13 snmp.py:875 snmp_set_check > snmp_set_check(('ntpPrimaryServer.0=33.33.1.2',)) > > snmp.py:913 snmp.py:808 snmp_set > snmp_set(('ntpPrimaryServer.0=33.33.1.2',)) > > snmp.py:914 snmp.py:683 snmp_get > snmp_get(('ntpPrimaryServer.0=33.33.1.2',)) > > robot_test.py:13 snmp.py:875 snmp_set_check > snmp_set_check(('ntpPrimaryServer.0=172.22.1.8',)) > > snmp.py:913 snmp.py:808 snmp_set > snmp_set(('ntpPrimaryServer.0=172.22.1.8',)) > > snmp.py:914 snmp.py:683 snmp_get > snmp_get(('ntpPrimaryServer.0=172.22.1.8',)) > > robot_test.py:15 snmp.py:875 snmp_set_check > snmp_set_check(('ntpClientEnabled.1=true',)) > > snmp.py:913 snmp.py:808 snmp_set > snmp_set(('ntpClientEnabled.1=true',)) > > snmp.py:857 snmp.py:683 snmp_get > snmp_get(('-s', 'lastSetErrorInformation.0')) > FAILED > ==============================End of Test Case > > robot_test.py:18: test_something_quick > ==============================Test Case: test_something_quick > > python.py:152 robot_test.py:18 test_something_quick > > test_something_quick > PASSED > ==============================End of Test Case > > robot_test.py:23: test_another > ==============================Test Case: test_another > > python.py:152 robot_test.py:23 test_another > PASSED > ==============================End of Test Case > > > ===================================================================== > FAILURES > ====================================================================== > _____________________________________________________________________ > test_ntp > ______________________________________________________________________ > > @pytest.mark.webtest > @pytest.mark.high > def test_ntp(): > host = snmp.Snmp() > host.snmp_connect(hostname='172.23.191.53', version=2, > community='private') > for ip in ('33.33.1.2', '172.22.1.8'): > host.snmp_set_check('ntpPrimaryServer.0=' + ip) > for ntpClientEnabled in ('true', 'false'): > > host.snmp_set_check('ntpClientEnabled.1=' + ntpClientEnabled) > > robot_test.py:15: > _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > > self = , args = ('ntpClientEnabled.1=true',), var_list > = [] > var_list_txt = [{'expect_value': 'true', 'index': '1', 'name': > 'ntpClientEnabled.1', 'noid': '.1.3.6.1.4.1.2544.1.12.2.1.10.1', ...}] > > @classmethod > def snmp_set_check(self, *args): > ''' > *Set and check a list of soids and values. * > > --Without '-N' (negative) tag, for example > snmp_set_check('ecpaControlDuration.1.1.1.1=20'), > set the ecpaControlDuration.1.1.1.1 to 20 and check result. > Test fail > - a, errors from Node: lastSetError > - b, timeout and other errors from netsnmp. > - c, Node and index Error etc from adva python snmp library. > - d, value not equal > > --With '-N' (negative) tag, for example > snmp_set('ecpaControlDuration.1.1.1.1=0, '-N'), > set the ecpaControlDuration.1.1.1.1 to 20 and Test fails if: > - a, set ok > - b, Node Error etc(index not included) from adva python snmp > library. > - c, timeout and other errors from netsnmp. > > | *Fixed argument* | *type* | *description* | > | *args | string | one or more string like > ecpaControlDuration.1.1.1.1=\ > 0, -N, ntpClientEnabled.0=false -c true | > > | *optional argument* | *type* | *description* | > | -N | bool switch | With this tag do Negative check. \ > Without this tag do normal check. | > > | *Return type* | *Example* | > | None | None | > > *--Robot Example* > | snmp_set_check | ntpClientEnabled.0=false -c true | \ > ecpaControlTestType.1.1.24.1=createAndGo | -N | > | snmp_set_check | ecpaControlTestType.1.1.24.1=createAndGo' | > ''' > print colors.yellow('\t\tsnmp_set_check({0})'.format(args)) > var_list, var_list_txt = _convert_args_to_list(args, > return_txt=True) > > snmp_result = Snmp.snmp_set(*args) > > /opt/adva/snmp.py:913: > _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > > self = , args = ('ntpClientEnabled.1=true',), var_list > = [] > var_list_txt = [{'expect_value': 'true', 'index': '1', 'name': > 'ntpClientEnabled.1', 'noid': '.1.3.6.1.4.1.2544.1.12.2.1.10.1', ...}] > snmp_result = 0 > > @classmethod > def snmp_set(self, *args): > ''' > --Set a list of soids and values. > > -Without '-N' (negative) tag, for example > snmp_set('ecpaControlDuration.1.1.1.1=20'), > set the ecpaControlDuration.1.1.1.1 to 20 . Test fail if: > - a, errors from Node: lastSetError > - b, timeout and other errors from netsnmp. > - c, Node and index Error etc from adva python snmp library. > > -With '-N' (negative) tag, for example > snmp_set('ecpaControlDuration.1.1.1.1=0, '-N'), > set the ecpaControlDuration.1.1.1.1 to 20 and Test fails if: > - a, set ok > - b, Node Error etc(index not included) from adva python snmp > library. > - c, timeout and other errors from netsnmp. > > | *Fixed argument* | *type* | *description* | > | *args | string | one or more string like > ecpaControlDuration.1.1.1.1=\ > 0, -N | > > | *optional argument* | *type* | *description* | > | -N | bool switch | With this tag do Negative check. \ > Without this tag do normal check. | > > | *Return type* | *Example* | > | None | None | > > *--Robot Example* > | snmp set | ecpaControlDuration.1.1.1.1=0 | -N | > | snmp set | ecpaControlDuration.1.1.1.1=20 | > ''' > > print colors.yellow('\t\tsnmp_set({0})'.format(args)) > > var_list, var_list_txt = _convert_args_to_list(args, > return_txt=True) > snmp_result = Snmp.client.set(var_list) > # netsnmp python binding return 0 if set fail, return 1 if set ok > # we need to convert it to the same format as snmp set. > if snmp_result == 1 and Snmp.reverse: > output_console_error( > "SnmpSetNegativeError", > str(args)) > if snmp_result == 1 and (not Snmp.reverse): > return > if snmp_result == 0 and (not Snmp.reverse): > #print colors.red('\t\t snmp_set Error') > error_info = Snmp.snmp_get('-s', "lastSetErrorInformation.0") > #print colors.red('\t\t lastSetErrorInformation: '), > > assert 0 == 1 > E assert 0 == 1 > > /opt/adva/snmp.py:859: AssertionError > ======================================================== 1 failed, 2 > passed in 2.34 seconds > ======================================================== > -------------- next part -------------- An HTML attachment was scrubbed... URL: