Python中文
首页
教程
问答
标签
搜索
登录
注册
如何在python中获得测试方法的起始行号和结束行号?
回答此问题可获得
20
贡献值,回答如果被采纳可获得
50
分。
<p>我目前正在尝试获取python文件中所有测试方法的第一行和最后一行。你知道吗</p> <p>例如:</p> <p>文件测试_电梯.py测试文件电梯.py. 你知道吗</p> <p><strong>测试_电梯.py</strong></p> <pre><code>1 import random 2 3 from src.lift import Lift 4 from flaky import flaky 5 6 7 def test_upwards(): 8 tester = Lift() 9 tester.upwards() 10 assert 1 == tester.curr_floor 11 12 def test_downwards(): 13 tester = Lift() 14 tester.curr_floor = 1 15 tester.downwards() 16 assert 0 == tester.curr_floor 17 tester.downwards() 18 assert 0 == tester.curr_floor 19 ... </code></pre> <p>我现在想得到test中每个测试方法的第一行和最后一行的编号_电梯.py,例如:</p> <p><em>向上测试,7,10</em></p> <p><em>向下测试,12,18</em></p> <p>我已经试过使用确认测试.py,但没有成功。也许我忽略了什么? 解决方案不一定必须是python。如果有人知道如何通过解析文件来解决这个问题,我可以接受。你知道吗</p>
0 条评论
分类:
Python问答
请先
登录
后评论
默认排序
时间排序
1 个回答
匿名
1天前
擅长:python、mysql、java
<p>您可以使用<code>inspect</code>模块来完成此任务</p> <pre><code>import inspect lines,line_start = inspect.getsourcelines(test_downwards) print("Lines:",line_start,line_start+len(lines) - 1 ) </code></pre>
请先
登录
后评论
针对此问题:
更多的回答
关注
89
关注
收藏
1
收藏,
216
浏览
网友 提问于 2天前
相关Python问题
如何提高Djang的410误差
6 回答
如何提高doc2vec模型中两个文档(句子)的余弦相似度?
5 回答
如何提高Docker的日志限制?|[输出已剪裁,达到日志限制100KiB/s]
8 回答
如何提高DQN的性能?
8 回答
如何提高EasyOCR的准确性/预测?
7 回答
如何提高Euler#39项目解决方案的效率?
6 回答
如何提高F1成绩进行分类
8 回答
如何提高FaceNet的准确性
5 回答
如何提高fft处理的精度?
4 回答
如何提高Fibonacci实现对大n的精度?
5 回答
如何提高Flask与psycopg2的连接时间
10 回答
如何提高FosterCauer变换的scipy.signal.invres()的数值稳定性?
7 回答
如何提高gae查询的性能?
4 回答
如何提高GANs用于时间序列预测/异常检测的结果
7 回答
如何提高gevent和tornado组合的性能?
1 回答
如何提高googleappengin请求日志的吞吐量
4 回答
如何提高googlevision文本识别的准确性
6 回答
如何提高groupby/apply效率
2 回答
如何提高Gunicorn中的请求率
2 回答
如何提高G中的文件编码转换
1 回答