Replacing test_osrandom_engine_is_default. (#2905)
* Removing test_osrandom_engine_is_default.
test_osrandom_engine_is_default depends on having a valid
sys.executable. This attribute is not always set (see
https://docs.python.org/2/library/sys.html#sys.executable ) so, in some
environments, this test fails. I moved the functionality of the test
into the setup and teardown methods so the correct behavior is still
tested.
* Fixing some style issues.
* Removing an unnecessary newline.
* Putting back the test.
* Moving the assert from teardown to setup.
diff --git a/tests/hazmat/backends/test_openssl.py b/tests/hazmat/backends/test_openssl.py
index 52bee7b..a24f8ec 100644
--- a/tests/hazmat/backends/test_openssl.py
+++ b/tests/hazmat/backends/test_openssl.py
@@ -208,6 +208,16 @@
class TestOpenSSLRandomEngine(object):
+
+ def setup(self):
+ # The default RAND engine is global and shared between
+ # tests. We make sure that the default engine is osrandom
+ # before we start each test and restore the global state to
+ # that engine in teardown.
+ current_default = backend._lib.ENGINE_get_default_RAND()
+ name = backend._lib.ENGINE_get_name(current_default)
+ assert name == backend._binding._osrandom_engine_name
+
def teardown_method(self, method):
# we need to reset state to being default. backend is a shared global
# for all these tests.
@@ -216,6 +226,8 @@
name = backend._lib.ENGINE_get_name(current_default)
assert name == backend._binding._osrandom_engine_name
+ @pytest.mark.skipif(sys.executable is None,
+ reason="No Python interpreter available.")
def test_osrandom_engine_is_default(self, tmpdir):
engine_printer = textwrap.dedent(
"""