Skip to content
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 random.seed call before every random usage #81

Merged
merged 2 commits into from
Jan 12, 2016

Conversation

elyezer
Copy link
Contributor

@elyezer elyezer commented Jan 12, 2016

Make sure to regenerate the seed every time before calling a random
function. This will make sure to generate different values even when
running on a multi-process testing environment like py.test using the
pytest-xdist plugin.

Make sure to regenerate the seed every time before calling a random
function. This will make sure to generate different values even when
running on a multi-process testing environment like py.test using the
pytest-xdist plugin.
@elyezer
Copy link
Contributor Author

elyezer commented Jan 12, 2016

Check the captured stdout for the generated value.

The result below was run against the following test file:

import unittest

from fauxfactory import gen_alphanumeric


class TestCase(unittest.TestCase):
    def test_1(self):
        print(gen_alphanumeric())
        self.fail()

    def test_2(self):
        print(gen_alphanumeric())
        self.fail()

Without the changes running on a single process mode:

$ py.test test.py       
================================ test session starts ================================
platform linux -- Python 3.4.2, pytest-2.8.2, py-1.4.30, pluggy-0.3.1
rootdir: /home/elyezer/code/robottelo, inifile: 
plugins: xdist-1.13.1, cov-2.2.0
collected 2 items 

test.py FF

===================================== FAILURES ======================================
__________________________________ TestCase.test_1 __________________________________

self = <test.TestCase testMethod=test_1>

    def test_1(self):
        print(gen_alphanumeric())
>       self.fail()
E       AssertionError: None

test.py:9: AssertionError
------------------------------- Captured stdout call --------------------------------
yTJmFRkBk8
__________________________________ TestCase.test_2 __________________________________

self = <test.TestCase testMethod=test_2>

    def test_2(self):
        print(gen_alphanumeric())
>       self.fail()
E       AssertionError: None

test.py:13: AssertionError
------------------------------- Captured stdout call --------------------------------
ld1Ar8wRw3
============================= 2 failed in 1.00 seconds ==============================

Without the changes running on a multi-process mode:

py.test -s -v -n auto --boxed --cache-clear test.py
================================ test session starts ================================
platform linux -- Python 3.4.2, pytest-2.8.2, py-1.4.30, pluggy-0.3.1 -- /home/elyezer/.virtualenvs/robottelo/bin/python3
cachedir: .cache
rootdir: /home/elyezer/code/robottelo, inifile: 
plugins: xdist-1.13.1, cov-2.2.0
[gw0] linux Python 3.4.2 cwd: /home/elyezer/code/robottelo
[gw1] linux Python 3.4.2 cwd: /home/elyezer/code/robottelo
[gw2] linux Python 3.4.2 cwd: /home/elyezer/code/robottelo
[gw3] linux Python 3.4.2 cwd: /home/elyezer/code/robottelo
[gw0] Python 3.4.2 (default, Jul  9 2015, 17:24:30)  -- [GCC 5.1.1 20150618 (Red Hat 5.1.1-4)]
[gw1] Python 3.4.2 (default, Jul  9 2015, 17:24:30)  -- [GCC 5.1.1 20150618 (Red Hat 5.1.1-4)]
[gw3] Python 3.4.2 (default, Jul  9 2015, 17:24:30)  -- [GCC 5.1.1 20150618 (Red Hat 5.1.1-4)]
[gw2] Python 3.4.2 (default, Jul  9 2015, 17:24:30)  -- [GCC 5.1.1 20150618 (Red Hat 5.1.1-4)]
gw0 [2] / gw1 [2] / gw2 [2] / gw3 [2]
scheduling tests via LoadScheduling
[gw0] FAILED test.py::TestCase::test_1 
[gw0] FAILED test.py::TestCase::test_2 

===================================== FAILURES ======================================
__________________________________ TestCase.test_1 __________________________________
[gw0] linux -- Python 3.4.2 /home/elyezer/.virtualenvs/robottelo/bin/python3
self = <test.TestCase testMethod=test_1>

    def test_1(self):
        print(gen_alphanumeric())
>       self.fail()
E       AssertionError: None

test.py:9: AssertionError
------------------------------- Captured stdout call --------------------------------
0fUWTQe18P
__________________________________ TestCase.test_2 __________________________________
[gw0] linux -- Python 3.4.2 /home/elyezer/.virtualenvs/robottelo/bin/python3
self = <test.TestCase testMethod=test_2>

    def test_2(self):
        print(gen_alphanumeric())
>       self.fail()
E       AssertionError: None

test.py:13: AssertionError
------------------------------- Captured stdout call --------------------------------
0fUWTQe18P
============================= 2 failed in 4.22 seconds ==============================

After the changes running on multi-process mode:

py.test -s -v -n auto --boxed test.py              
================================ test session starts ================================
platform linux -- Python 3.4.2, pytest-2.8.2, py-1.4.30, pluggy-0.3.1 -- /home/elyezer/.virtualenvs/robottelo/bin/python3
cachedir: .cache
rootdir: /home/elyezer/code/robottelo, inifile: 
plugins: xdist-1.13.1, cov-2.2.0
[gw0] linux Python 3.4.2 cwd: /home/elyezer/code/robottelo
[gw1] linux Python 3.4.2 cwd: /home/elyezer/code/robottelo
[gw2] linux Python 3.4.2 cwd: /home/elyezer/code/robottelo
[gw3] linux Python 3.4.2 cwd: /home/elyezer/code/robottelo
[gw0] Python 3.4.2 (default, Jul  9 2015, 17:24:30)  -- [GCC 5.1.1 20150618 (Red Hat 5.1.1-4)]
[gw1] Python 3.4.2 (default, Jul  9 2015, 17:24:30)  -- [GCC 5.1.1 20150618 (Red Hat 5.1.1-4)]
[gw2] Python 3.4.2 (default, Jul  9 2015, 17:24:30)  -- [GCC 5.1.1 20150618 (Red Hat 5.1.1-4)]
[gw3] Python 3.4.2 (default, Jul  9 2015, 17:24:30)  -- [GCC 5.1.1 20150618 (Red Hat 5.1.1-4)]
gw0 [2] / gw1 [2] / gw2 [2] / gw3 [2]
scheduling tests via LoadScheduling
[gw2] FAILED test.py::TestCase::test_1 
[gw2] FAILED test.py::TestCase::test_2 

===================================== FAILURES ======================================
__________________________________ TestCase.test_1 __________________________________
[gw2] linux -- Python 3.4.2 /home/elyezer/.virtualenvs/robottelo/bin/python3
self = <test.TestCase testMethod=test_1>

    def test_1(self):
        print(gen_alphanumeric())
>       self.fail()
E       AssertionError: None

test.py:9: AssertionError
------------------------------- Captured stdout call --------------------------------
5eBetOyxGv
__________________________________ TestCase.test_2 __________________________________
[gw2] linux -- Python 3.4.2 /home/elyezer/.virtualenvs/robottelo/bin/python3
self = <test.TestCase testMethod=test_2>

    def test_2(self):
        print(gen_alphanumeric())
>       self.fail()
E       AssertionError: None

test.py:13: AssertionError
------------------------------- Captured stdout call --------------------------------
5WG86PBIEZ
============================= 2 failed in 4.03 seconds ==============================

@omaciel
Copy link
Owner

omaciel commented Jan 12, 2016

APT

Also remove pylint check from travis since there is an issue with Python
2.6.
omaciel added a commit that referenced this pull request Jan 12, 2016
Add random.seed call before every random usage
@omaciel omaciel merged commit 1bb9e70 into omaciel:master Jan 12, 2016
@elyezer elyezer deleted the random-seed branch January 13, 2016 10:09
JacobCallahan added a commit to JacobCallahan/fauxfactory that referenced this pull request Aug 27, 2022
I changed the random selection of some methods from comprehensions to
uses of random.choices. Most improved by around 15%.
However, gen_cjk saw a 5.5x speedup!

I then took it a bit further by moving random.seed out of each method call
and into the module scope.
This greatly improved the runtime of each changed method.
Additionally, it should still alleviate the original concern solved with omaciel#81
JacobCallahan added a commit to JacobCallahan/fauxfactory that referenced this pull request Aug 27, 2022
I changed the random selection of some methods from comprehensions to
uses of random.choices. Most improved by around 15%.
However, gen_cjk saw a 5.5x speedup!

I then took it a bit further by moving random.seed out of each method call
and into the module scope.
This greatly improved the runtime of each changed method.
Additionally, it should still alleviate the original concern solved with omaciel#81
omaciel pushed a commit that referenced this pull request Aug 29, 2022
I changed the random selection of some methods from comprehensions to
uses of random.choices. Most improved by around 15%.
However, gen_cjk saw a 5.5x speedup!

I then took it a bit further by moving random.seed out of each method call
and into the module scope.
This greatly improved the runtime of each changed method.
Additionally, it should still alleviate the original concern solved with #81
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants