简体   繁体   English

使用Python的J Meter:如何导入包

[英]J meter with Python : how to import the packages

Iam new bee to the jmeter IAM新蜜蜂到Jmeter

My code is working in the Python 2.7 with importing additional packages Dateutil, parser . 我的代码在Python 2.7中正常工作,并导入了其他软件包Dateutil,parser。

Problme : But when I am trying to run same code in the J Meter-JSR-223 PreProcessors , an error saying No module named dateutil in. 问题:但是当我尝试在J Meter-JSR-223 PreProcessors中运行相同的代码时,出现错误,提示没有名为dateutil的模块进入。

So , I have tried another approach to use Jython . 因此,我尝试了另一种使用Jython的方法。

Installed the Jython ( downloaded the dateutil) and provide the packages reference under 安装了Jython(下载了dateutil)并在下面提供了软件包参考

import sys
sys.path.append('C:/Jython27/Lib/site-packages')
sys.path.append('C:/Jython27/Lib/site-packages/python_dateutil-2.4.2-py2.7/dateutil')
sys.path.append('C:/Jython27/Lib/site-packages/python_dateutil-2.4.2-py2.7/dateutil')

Now packages error is gone but string syntax error is present . java.sql.Date' object has no attribute . 现在包错误消失了,但是字符串语法错误出现了. java.sql.Date' object has no attribute . . java.sql.Date' object has no attribute .

I believe dateutil package can be picked up from CPython as it doesn't require any extra wrappers for Java. 我相信dateutil包可以从CPython中获取,因为它不需要Java的任何额外包装。

  1. Install dateutil normally using pip like: 通常使用pip安装dateutil,例如:

     pip install python-dateutil 
  2. Add site-packages folder of Python (not Jython) installation to sys.path like: 将Python(不是Jython)安装的site-packages文件夹添加到sys.path中,如下所示:

     sys.path.append("C:\\Python27\\Lib\\site-packages") 
  3. That's it, now you should be able to use dateutil module functions from the JSR223 Test Elements: 就是这样,现在您应该能够使用JSR223测试元素中的dateutil模块功能:

    在此处输入图片说明


Be aware that invoking Python scripts via Jython interpreter is not the best idea from performance perspective and if you're about to invoke your Python code only limited number of times and/or with a single thread - it might be better to go for the OS Process Sampler . 请注意,从性能的角度来看,通过Jython解释器调用Python脚本不是最好的主意,并且如果您仅要有限次数地和/或使用一个线程来调用Python代码,则最好使用OS工艺取样器

If you plan to use the Python code to create the main load - consider using Locust tool instead of JMeter. 如果计划使用Python代码创建主负载,请考虑使用Locust工具而不是JMeter。 If you don't want to change JMeter a good approach would be rewriting your Python code in Groovy - it will be way better from the performance perspective. 如果您不想更改JMeter,那么一种好的方法是用Groovy重写Python代码-从性能的角度来看会更好。

hi please find follwing 嗨,请跟随

import sys
sys.path.append('C:/Python27/Lib/site-packages')
sys.path.append('C:/Python27/Lib/site-packages/python_dateutil-2.4.2-py2.7/dateutil')

from dateutil.parser import *
sourceDateTimeOfEvent = ""
dateTimeOfEvent = ""

a=parse('2016-07-01 13:00:00')
sourceDateTimeOfEvent = a.isoformat()+"+05:30Z"
dateTimeOfEvent = a.isoformat()+ "Z"

vars.put("sourceDateTimeOfEvent", sourceDateTimeOfEvent)
vars.put("dateTimeOfEvent", dateTimeOfEvent)

This sourceDateTimeOfEvent and dateTimeOfEvent considered as two variables and passed it to the json file 此sourceDateTimeOfEvent和dateTimeOfEvent被视为两个变量,并将其传递给json文件

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM