There are some things to watch out for when using jython/python in JSR223 code in Jmeter.
As Jython is a java implementation of Python you may come across some “Type” bugs.
Let’s look at the datetime object.
If we wanted to create 2 variables for our script, 1 being the current datetime and the other being 10 days from now.
This is a common case when scripting for airline flights.
In native Python we can just do something like:
However when using this in jmeter JSR223 code we get the following error.
This is because of a “TypeError”. When Jython assigns a datetime object to a variable, it transforms it to a java.sql.Timestamp object.
So, in order to use datetime objects in jython, you need to use them immediately and not assign them to a variable.
This makes the code less eloquent, but it looks like this “bug/feature” won’t be fixed, so you will have to use this workaround.