[TIP] question re: tox and PYTHONHASHSEED

holger krekel holger at merlinux.eu
Wed Sep 25 22:39:46 PDT 2013


On Wed, Sep 25, 2013 at 18:29 -0700, Chris Jerdonek wrote:
> On Wed, Sep 25, 2013 at 3:53 PM, Chris Jerdonek
> <chris.jerdonek at gmail.com> wrote:
> > I have a question about tox.  What options do I have for setting
> > PYTHONHASHSEED [1] to an explicit random integer value prior to each
> > tox test run?
> 
> By the way, I tried the following two work-arounds in my tox.ini, and
> neither worked:
> 
> commands =
>     export PYTHONHASHSEED=$RANDOM && run_tests

Tox does not support this bash syntax (would be cool if it did implement
a subset of bash functionality, no question).

I don't see a direct way of setting a different-per-tox-run PYTHONHASHSEED
at the moment, other than introducing a {RANDOMSEED} subsitution which
you could then use like this::

    setenv =
        PYTHONHASHSEED={RANDOMSEED}

which would take effect for installation and test commands.
We could also have a --randomseed option to force it to a particular
value to be able to repeat a run.  If that makes sense to you
please open a feature issue and (at best) go for a pull request.

cheers,
holger

> py33 runtests: commands[0] | export PYTHONHASHSEED=$RANDOM && run_tests
> ERROR: InvocationError: could not find executable 'export'
> 
> commands =
>     echo "foo" && export PYTHONHASHSEED=$RANDOM && run_tests
> 
> py33 runtests: commands[0] | echo foo && export PYTHONHASHSEED=$RANDOM
> && run-tests
> WARNING:test command found but not installed in testenv
>   cmd: /bin/echo
>   env: /.../.tox/py33
> Maybe forgot to specify a dependency?
> foo && export PYTHONHASHSEED=$RANDOM && run-tests
> 
> In the latter example, it is "echoing" the rest of the command.
> 
> --Chris
> 
> 
> 
> 
> 
> 
> 
> >
> > Specifically, my tox command calls a Python test script generated from
> > a setup.py console_script entry_point.  For debugging purposes, my
> > test script displays the value of PYTHONHASHSEED at the beginning of
> > each test run.  If PYTHONHASHSEED is an integer as opposed to
> > "random", this lets me re-run the tests with the same hash seed.
> >
> > I would like to set PYTHONHASHSEED to a random integer for each tox
> > test run.  When running tests from source (without tox), I can do this
> > using a wrapper shell script that sets PYTHONHASHSEED as follows prior
> > to calling the Python script:
> >
> >     export PYTHONHASHSEED=$RANDOM
> >
> > What options do I have for doing something similar with tox?  For
> > example, it would be nice to be able to do something like the
> > following in my tox.ini:
> >
> >     setenv =
> >         PYTHONHASHSEED = $RANDOM
> >
> > --Chris
> >
> > [1] http://docs.python.org/2/using/cmdline.html#envvar-PYTHONHASHSEED
> 
> _______________________________________________
> testing-in-python mailing list
> testing-in-python at lists.idyll.org
> http://lists.idyll.org/listinfo/testing-in-python
> 



More information about the testing-in-python mailing list