From fa54884131956a1f1321f9a42511cfc8d91d4ad9 Mon Sep 17 00:00:00 2001 From: Simon Gomizelj Date: Sat, 31 Mar 2018 02:51:48 -0400 Subject: [PATCH] Fix unit tests when run with PYTHONDONTWRITEBYTECODE When set, it will conflict with any tests that generate bytecode because they don't expect it to be set. Fixable by sanitize the environment before forking, but we can't do anything about import tests. This is a pipenv default, and possibly a sane flag to set while doing Hy development, so lets not let it be a hazard for developers to trip over. --- tests/importer/test_importer.py | 3 +++ tests/test_bin.py | 6 ++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/tests/importer/test_importer.py b/tests/importer/test_importer.py index 9e61838..31b4705 100644 --- a/tests/importer/test_importer.py +++ b/tests/importer/test_importer.py @@ -10,6 +10,7 @@ import os import ast import tempfile from fractions import Fraction +import pytest def test_basics(): @@ -50,6 +51,8 @@ def test_import_error_reporting(): assert _import_error_test() is not None +@pytest.mark.skipif(os.environ.get('PYTHONDONTWRITEBYTECODE'), + reason="Bytecode generation is suppressed") def test_import_autocompiles(): "Test that (import) byte-compiles the module." diff --git a/tests/test_bin.py b/tests/test_bin.py index abad9ca..7b34007 100644 --- a/tests/test_bin.py +++ b/tests/test_bin.py @@ -24,10 +24,12 @@ def hr(s=""): def run_cmd(cmd, stdin_data=None, expect=0, dontwritebytecode=False): - env = None + env = dict(os.environ) if dontwritebytecode: - env = dict(os.environ) env["PYTHONDONTWRITEBYTECODE"] = "1" + else: + env.pop("PYTHONDONTWRITEBYTECODE", None) + cmd = shlex.split(cmd) cmd[0] = os.path.join(hy_dir, cmd[0]) p = subprocess.Popen(cmd,