3
class TestRunner:
    def __call__(self):
        user1()
        user2()
        user3()
        user4()

How do I execute the users randomly in jython, to run in grinder tool?

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
srp
  • 521
  • 11
  • 22
  • 1
    Exactly one execution per user (shuffle them / Martijn's answer), or execute a random user each time this is called (take a random one / Lionel's answer)? – tucuxi Sep 12 '12 at 10:18
  • nice to know..valuable information.. thank you – srp Sep 12 '12 at 10:41

2 Answers2

6

Store the functions in a list (without calling them), then use random.shuffle:

import random

class TestRunner:
    def __call__(self):
        users = [user1, user2, user3, user4]
        random.shuffle(users)
        for user in users:
            user()
Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
4

I don't know jython, but if you want a random choice, this should work

import random
class TestRunner:
    def __call__(self):
        func = random.choice([user1, user2, user3, user3])
        func()
LBarret
  • 1,113
  • 10
  • 23