Python - Some useful Pytest Commands
Introduction In this post, we will explore some useful command line options for…
September 14, 2018
I was testing a bug where a field was limited to 255 characters only. I needed to generate a string of more than 255 characters.
The simplest code I found:
# Generate string of only character 'a' 300 times
'a' * 300
This will generate a string of 300 characters
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa......
Or, you can mix characters
'a' * 100 + 'b' * 100 + 'hey master'
def gen(character, length):
return character * length
# to use
>>> gen('a',20)
'aaaaaaaaaaaaaaaaaaaa'
>>> gen('a',20) + gen('b',10)
'aaaaaaaaaaaaaaaaaaaabbbbbbbbbb'
Using module random
import string
import random
# for upper case ascii characters, and 10 characters long
''.join(random.choice(string.ascii_uppercase) for _ in range(10))
# In a method
def generate(characters=string.ascii_uppercase, length = 10):
return ''.join(random.choice(characters) for _ in range(length))
>>> generate()
'GSPUYMYMLB'
# For having upper case as well as numerics
>>> generate(characters=string.ascii_uppercase + string.digits)
'X9O814PS58'
# For longer string
>>> generate(characters=string.ascii_uppercase + string.digits, length=20)
'7HCYBJAQP9N48TC179Q8'
Introduction In this post, we will explore some useful command line options for…
Introduction While this topic may applicable to all mysql/mariadb users who…
Introduction Suppose you have a view, and you have configured your display as a…
Introduction I was trying to download some youtube videos for my kids. As I have…
Introduction In this post, we will learn about some of Best practices while…
While writing JUnit test cases, we encounter cases like we want to initialize a…
Introduction This post has the complete code to send email through smtp server…
Introduction In a normal email sending code from python, I’m getting following…
Introduction In one of my app, I was using to talk to . I have used some event…
Introduction So you have a Django project, and want to run it using docker image…
Introduction It is very important to introduce few process so that your code and…
Introduction In this post, we will see a sample Jenkin Pipeline Groovy script…