且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

写完测试脚本怎么运行都是错误的原来是着了“VSCode设置自动保存”的道

更新时间:2022-04-13 07:30:37

问题

升级了Locust,发现原来的脚本都不可以用,赶紧查询一下发现HttpLocust变成了HttpUser,tasek_set变成了tasks,这也是小CASE,修改后,怎么运行都报错,错误如下:

[2021-10-21 09:06:36,789] bogon/ERROR/locust.user.task: No tasks defined on WebsiteUser. use the @task decorator or set the tasks property of the User (or mark it as abstract = True if you only intend to subclass it)
Traceback (most recent call last):
  File "/Users/crisschan/Library/Python/3.8/lib/python/site-packages/locust/user/task.py", line 291, in run
    self.schedule_task(self.get_next_task())
  File "/Users/crisschan/Library/Python/3.8/lib/python/site-packages/locust/user/task.py", line 423, in get_next_task
    raise Exception(
Exception: No tasks defined on WebsiteUser. use the @task decorator or set the tasks property of the User (or mark it as abstract = True if you only intend to subclass it)

百思不得其解,一个类名的变更为什么出错呢?

后来发现,原来修改完代码没有点击保存,因此每次运行都是保存前的代码,以前用Pycharm都自动保存,VSCode难道就不可以吗?

解决:VSCode的自动保存

VSCode当然可以自动保存,进入“file->Preferences->setting->搜索auto save“:

写完测试脚本怎么运行都是错误的原来是着了“VSCode设置自动保存”的道

你会发现自动保存有4中模式可选,分别是:

  • off:关闭
  • afterDelay:修改后,延迟多长时间后自动保存,时间可以在下面的Auto Save Delay中设置
  • OnFouseChange:当代码编辑框焦点改变的时候保存
  • OnWindowChange:当VSCode焦点变化的时候保存

选择每一个在下面都有对应的解释,我更喜欢无论如何你都自动保存(反正有撤销编辑功能),因此我选择了afterDelay的自动保存设置。