python怎么选取几个测试文件

python怎么选取几个测试文件,第1张

如何使用多个 locustfiles 运行 locust 测试。 locust 文档对如何执行此 *** 作不是很清楚。

最佳答案

在不同的文件中编写测试。确保每个文件中的类以不同的方式命名。

将所有不同文件中的类导入 locustfile.py (它可以有任何名称,不必是 locustfile.py )

例子。

testfile1.py

from locust import HttpUser, task, between, tag

class WebTests1(HttpUser):

wait_time = between(0,0.1)

def on_start(self):

# on_start is called when a Locust start before any task is scheduled.

pass

def on_stop(self):

# on_stop is called when the TaskSet is stopping

pass

@task(1)

def testaURL1(self):

response = self.client.post("/api/test/url1",

name="test url",

data="some json data",

headers="headers")

testfile2.py

from locust import HttpUser, task, between, tag

class WebTests2(HttpUser):

wait_time = between(0,0.1)

def on_start(self):

# on_start is called when a Locust start before any task is scheduled.

pass

def on_stop(self):

# on_stop is called when the TaskSet is stopping

pass

@task(1)

def testaURL2(2self):

response = self.client.post("/api/test/url2",

name="test url",

data="some json data",

headers="headers")

locustfile.py

from testfile1 import WebTests1

from testfile2 import WebTests2

将所有文件保存在同一目录中并运行 cmd locust或 locust -f locustfile.py它建议您遵循 Python 最佳实践来构建测试代码。引用:https://docs.locust.io/en/stable/writing-a-locustfile.html#how-to-structure-your-test-code

关于python - 如何使用多个测试文件运行 locust,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66771955/

上一篇:python - Django:您正在尝试添加一个不可为空的字段 'slug' 以在没有默认值的情况下发布;我们不能那样做

下一篇:java - 自签名应用 itext 5.5.11 以来,文档已被更改或损坏

相关文章:

javascript - 创建一个大型的Node.js缓存

python - 是否可以在locust.io的WEB输出数据中合并类似的GET请求?

python - 我如何知道将数据输入到keras RNN中的正确格式?

python - 如何知道脚本是从 django 还是从 cli 运行的

performance - PHP5-FPM随机开始消耗大量CPU

python - 如何解读 Locust 的指标?

debugging - 如何在轨迹测试中保留 session 和 CSRF token

python - 将元组转换为字典

python - 如何解决“找不到本地Berkeley DB”错误?

mysql - 在MySQL上执行SQL查询需要三秒钟,而无需更改数据库或SQL查询

叫循环自动读取。

对于开发人员来说,前者在需要重复 *** 作的时候可能会用到,当然,在选择文件的时候,可以使用os.walk(),这样就可以实现for循环自动读取,但是这个对于少量不停要换地址的文件选取有独特的优势,在数据处理中,d窗实现可以降低输入量,其实蛮好的。

import subprocess

subprocess.Popen("explorer /select,\"" + "C:\Users\sss" + "\\")

这样就不会出现黑窗口了

希望对你有所帮助~~


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/tougao/11740152.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-18
下一篇 2023-05-18

发表评论

登录后才能评论

评论列表(0条)

保存