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 <[email protected]>
> 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 <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 <[email protected]
> > <mailto:[email protected]>>
> >
> > 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
> > [email protected] <mailto:[email protected]>
> > http://mail.python.org/__mailman/listinfo/pytest-dev
> > <http://mail.python.org/mailman/listinfo/pytest-dev>
> >
> >
> >
>
>
_______________________________________________
Pytest-dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pytest-dev