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

Test state is leaking between tests #38

Open
ericdill opened this issue Apr 12, 2017 · 1 comment
Open

Test state is leaking between tests #38

ericdill opened this issue Apr 12, 2017 · 1 comment

Comments

@ericdill
Copy link
Contributor

ericdill commented Apr 12, 2017

With this test file test_leaky_state.py:

import spylon.spark.launcher as sparklauncher
import os

def test_set_spark_property():
    c = sparklauncher.SparkConfiguration()
    c.driver_memory = "4g"

def test_spark_driver_memory():
    c = sparklauncher.SparkConfiguration()
    c.conf.spark.driver.memory = "5g"
    c._set_environment_variables()
    assert '--driver-memory 5g' in os.environ['PYSPARK_SUBMIT_ARGS']

If I run test_spark_driver_memory by itself, it passes just fine:

$ python run_tests.py tests/test_leaky_state.py -k driver -v
========================================================================================================================================================================= test session starts =========================================================================================================================================================================
platform darwin -- Python 3.5.3, pytest-3.0.7, py-1.4.33, pluggy-0.4.0
rootdir: /Users/edill/dev/maxpoint/github/spylon, inifile:
collected 2 items 

tests/test_leaky_state.py::test_spark_driver_memory PASSED

========================================================================================================================================================================= 1 tests deselected ==========================================================================================================================================================================
=============================================================================================================================================================== 1 passed, 1 deselected in 0.29 seconds ================================================================================================================================================================
Name                            Stmts   Miss  Cover
---------------------------------------------------
spylon/__init__.py                  4      0   100%
spylon/_version.py                261    143    45%
spylon/common.py                   62     40    35%
spylon/spark/__init__.py            4      0   100%
spylon/spark/launcher.py          286    126    56%
spylon/spark/progress.py           76     65    14%
spylon/spark/yarn_launcher.py     144    119    17%
tests/test_leaky_state.py          10      2    80%
---------------------------------------------------
TOTAL                             847    495    42%

But if I run the two of these together, notably with test_set_spark_priority first, then test_spark_driver_memory fails

$ python run_tests.py tests/test_leaky_state.py -v
========================================================================================================================================================================= test session starts =========================================================================================================================================================================
platform darwin -- Python 3.5.3, pytest-3.0.7, py-1.4.33, pluggy-0.4.0 -- /Users/edill/miniconda/envs/spylon/bin/python
cachedir: .cache
rootdir: /Users/edill/dev/maxpoint/github/spylon, inifile:
collected 2 items 

tests/test_leaky_state.py::test_set_spark_property PASSED
tests/test_leaky_state.py::test_spark_driver_memory FAILED

============================================================================================================================================================================== FAILURES ===============================================================================================================================================================================
______________________________________________________________________________________________________________________________________________________________________ test_spark_driver_memory _______________________________________________________________________________________________________________________________________________________________________

    def test_spark_driver_memory():
        c = sparklauncher.SparkConfiguration()
        c.conf.spark.driver.memory = "5g"
        c._set_environment_variables()
>       assert '--driver-memory 5g' in os.environ['PYSPARK_SUBMIT_ARGS']
E       AssertionError: assert '--driver-memory 5g' in '--driver-memory 4g pyspark-shell'

tests/test_leaky_state.py:12: AssertionError
================================================================================================================================================================= 1 failed, 1 passed in 0.34 seconds ==================================================================================================================================================================
Name                            Stmts   Miss  Cover
---------------------------------------------------
spylon/__init__.py                  4      0   100%
spylon/_version.py                261    143    45%
spylon/common.py                   62     40    35%
spylon/spark/__init__.py            4      0   100%
spylon/spark/launcher.py          286    124    57%
spylon/spark/progress.py           76     65    14%
spylon/spark/yarn_launcher.py     144    119    17%
tests/test_leaky_state.py          10      0   100%
---------------------------------------------------
TOTAL                             847    491    42%
@ericdill
Copy link
Contributor Author

ericdill commented Apr 12, 2017

Ok so this was coming from setting an instance variable as a class attribute in the __init__. This is the fix

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

No branches or pull requests

1 participant