-
Notifications
You must be signed in to change notification settings - Fork 115
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add pytest option to randomly select and run number/percentage of tests from the collection. #15450
Add pytest option to randomly select and run number/percentage of tests from the collection. #15450
Conversation
33c747a
to
6d28232
Compare
|
PRT Result
|
|
PRT Result
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you generate a random seed that would be logged before use? Also, adding the option to pass a specific seed would allow us to repeat a random test selection.
I don't completely understand what you mean here. As per @jyejare's request he'd like user to specify the number/percentage of tests to collect. Or did you mean if no value is provided we should pick random number of tests? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed with Jake. It should be really simple to implement. With the current implementation, it should be only a matter of running random.seed(seed)
.
def random_pick(items, k, seed=None):
if seed is not None:
random.seed(seed)
return random.sample(items, k)
items = [1,2,3,4,5,6,7,8,9,10]
k = 2
seed = 42
picked_items = random_pick(items, k, seed)
print(f"Picked {k} random items (seed: {seed}):", picked_items)
# Picked 2 random items (seed: 42): [2, 1]
picked_items = random_pick(items, k, seed)
print(f"Picked {k} random items (seed: {seed}):", picked_items)
#Picked 2 random items (seed: 42): [2, 1]
picked_items = random_pick(items, k, seed)
print(f"Picked {k} random items (seed: {seed}):", picked_items)
#Picked 2 random items (seed: 42): [2, 1]
Edit: If you will implement this logic, you will also need to define a new cmd option to allow the user to pass the seed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree with @JacobCallahan, there should be a way to rerun the same set of tests. There's a good tip how to implement "seed" from @ogajduse. But if you're not going to implement the seed, there should be at least a log entry that contains all the selected test, which should be easily copy&pasted.
6d28232
to
fb5d082
Compare
Ah, now I get what Jake meant. Thanks for explaining:) Implemented your suggestion. |
Check the logs/robottelo.log for seed value.
|
aa86e2a
to
0d7f239
Compare
0d7f239
to
ea6a0db
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure about Automation team needs, but current solution seems to be able to select testcases randomly and also replay the same set of tests. The replay using seed breaks as soon as test collection is modified, but I don't think this is a problem. ACK
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice!!
…ts from the collection. (SatelliteQE#15450) Add pytest option to collect N random tests
Problem Statement
Solution
--select-random-tests
: Number/Percentage of tests to randomly select and run from selected test collection.--random-seed
: Seed value for random test collection. It should be used with --select-random-tests option.Examples
pytest tests/foreman/ --select-random-tests '5%'
pytest tests/foreman/ --select-random-tests 4 --random-seed fsdaxv
Related Issues