gilch: @Kodiologist Conflicting files, can you fix that? News should be easy. #1307 also affected that test file. You wrote #1269 in the first place, and this seems like a simple amendment. Otherwise, it looks okay to me. The test looks more complex but Travis passed it. 

After fixing the conflict, try breaking the flag PYTHONDONTWRITEBYTECODE detection to make sure the test still catches it.
diff --git a/NEWS b/NEWS
index 1a6c3d5e..b99e2285 100644
--- a/NEWS
+++ b/NEWS
@@ -8,6 +8,7 @@ Changes from 0.13.0
    [ Bug Fixes ]
    * Numeric literals are no longer parsed as symbols when followed by a dot
      and a symbol
+   * Hy now respects the environment variable PYTHONDONTWRITEBYTECODE
 
 Changes from 0.12.1
 
diff --git a/hy/importer.py b/hy/importer.py
index 878e1be5..ec3b606e 100644
--- a/hy/importer.py
+++ b/hy/importer.py
@@ -96,13 +96,14 @@ def import_file_to_module(module_name, fpath, loader=None):
             module = imp.new_module(module_name)
             module.__file__ = fpath
             code = ast_compile(_ast, fpath, "exec")
-            try:
-                write_code_as_pyc(fpath, code)
-            except (IOError, OSError):
-                # We failed to save the bytecode, probably because of a
-                # permissions issue. The user only asked to import the
-                # file, so don't bug them about it.
-                pass
+            if not os.environ.get('PYTHONDONTWRITEBYTECODE'):
+                try:
+                    write_code_as_pyc(fpath, code)
+                except (IOError, OSError):
+                    # We failed to save the bytecode, probably because of a
+                    # permissions issue. The user only asked to import the
+                    # file, so don't bug them about it.
+                    pass
             eval(code, module.__dict__)
         except (HyTypeError, LexException) as e:
             if e.source is None:

Hy Ignores PYTHONDONTWRITEBYTECODE
When `PYTHONDONTWRITEBYTECODE` is set in the environment (for example using `export PYTHONDONTWRITEBYTECODE=1`) Hy should not generate `.pyc`.
diff --git a/tests/test_bin.py b/tests/test_bin.py
index 8f72962e..c2e31e96 100644
--- a/tests/test_bin.py
+++ b/tests/test_bin.py
@@ -9,6 +9,7 @@ import subprocess
 import re
 from hy._compat import PY3
 from hy.importer import get_bytecode_path
+import pytest
 
 
 hy_dir = os.environ.get('HY_DIR', '')
@@ -18,13 +19,18 @@ def hr(s=""):
     return "hy --repl-output-fn=hy.contrib.hy-repr.hy-repr " + s
 
 
-def run_cmd(cmd, stdin_data=None, expect=0):
+def run_cmd(cmd, stdin_data=None, expect=0, dontwritebytecode=False):
+    env = None
+    if dontwritebytecode:
+        env = dict(os.environ)
+        env["PYTHONDONTWRITEBYTECODE"] = "1"
     p = subprocess.Popen(os.path.join(hy_dir, cmd),
                          stdin=subprocess.PIPE,
                          stdout=subprocess.PIPE,
                          stderr=subprocess.PIPE,
                          universal_newlines=True,
-                         shell=True)
+                         shell=True,
+                         env=env)
     if stdin_data is not None:
         p.stdin.write(stdin_data)
         p.stdin.flush()
@@ -240,39 +246,42 @@ def test_bin_hy_no_main():
     assert "This Should Still Work" in output
 
 
-def test_bin_hy_byte_compile():
+@pytest.mark.parametrize('scenario', [
+    "normal", "prevent_by_force", "prevent_by_env"])
+@pytest.mark.parametrize('cmd_fmt', [
+    'hy {fpath}', 'hy -m {modname}', "hy -c '(import {modname})'"])
+def test_bin_hy_byte_compile(scenario, cmd_fmt):
 
     modname = "tests.resources.bin.bytecompile"
     fpath = modname.replace(".", "/") + ".hy"
-
-    for can_byte_compile in [True, False]:
-        for cmd in ["hy " + fpath,
-                    "hy -m " + modname,
-                    "hy -c '(import {})'".format(modname)]:
-
-            rm(get_bytecode_path(fpath))
-
-            if not can_byte_compile:
-                # Keep Hy from being able to byte-compile the module by
-                # creating a directory at the target location.
-                os.mkdir(get_bytecode_path(fpath))
-
-            # Whether or not we can byte-compile the module, we should be able
-            # to run it.
-            output, _ = run_cmd(cmd)
-            assert "Hello from macro" in output
-            assert "The macro returned: boink" in output
-
-            if can_byte_compile:
-                # That should've byte-compiled the module.
-                assert os.path.exists(get_bytecode_path(fpath))
-
-            # When we run the same command again, and we've byte-compiled the
-            # module, the byte-compiled version should be run instead of the
-            # source, in which case the macro shouldn't be run.
-            output, _ = run_cmd(cmd)
-            assert ("Hello from macro" in output) ^ can_byte_compile
-            assert "The macro returned: boink" in output
+    cmd = cmd_fmt.format(**locals())
+
+    rm(get_bytecode_path(fpath))
+
+    if scenario == "prevent_by_force":
+        # Keep Hy from being able to byte-compile the module by
+        # creating a directory at the target location.
+        os.mkdir(get_bytecode_path(fpath))
+
+    # Whether or not we can byte-compile the module, we should be able
+    # to run it.
+    output, _ = run_cmd(cmd, dontwritebytecode=scenario == "prevent_by_env")
+    assert "Hello from macro" in output
+    assert "The macro returned: boink" in output
+
+    if scenario == "normal":
+        # That should've byte-compiled the module.
+        assert os.path.exists(get_bytecode_path(fpath))
+    elif scenario == "prevent_by_env":
+        # No byte-compiled version should've been created.
+        assert not os.path.exists(get_bytecode_path(fpath))
+
+    # When we run the same command again, and we've byte-compiled the
+    # module, the byte-compiled version should be run instead of the
+    # source, in which case the macro shouldn't be run.
+    output, _ = run_cmd(cmd)
+    assert ("Hello from macro" in output) ^ (scenario == "normal")
+    assert "The macro returned: boink" in output
 
 
 def test_bin_hy_module_main():

pip install -e .
parse_log_pytest
pytest
pytest
3.6
pytest --no-header -rA --tb=line --color=no -p no:cacheprovider -W ignore::DeprecationWarning
appdirs==1.4.4
args==0.1.0
astor==0.8.1
attrs @ file:///opt/conda/conda-bld/attrs_1642510447205/work
certifi==2021.5.30
clint==0.5.1
-e git+https://github.com/hylang/hy.git@672c8a1637c7ad5c5cc0ce8c77e044c99631a47e#egg=hy
importlib-metadata @ file:///tmp/build/80754af9/importlib-metadata_1631916693255/work
iniconfig @ file:///home/linux1/recipes/ci/iniconfig_1610983019677/work
more-itertools @ file:///tmp/build/80754af9/more-itertools_1637733554872/work
packaging @ file:///tmp/build/80754af9/packaging_1637314298585/work
pluggy @ file:///tmp/build/80754af9/pluggy_1615976315926/work
py @ file:///opt/conda/conda-bld/py_1644396412707/work
pyparsing @ file:///tmp/build/80754af9/pyparsing_1635766073266/work
pytest==6.2.4
rply==0.7.8
toml @ file:///tmp/build/80754af9/toml_1616166611790/work
typing_extensions @ file:///opt/conda/conda-bld/typing_extensions_1647553014482/work
zipp @ file:///tmp/build/80754af9/zipp_1633618647012/work

name: hy
channels:
  - defaults
  - https://repo.anaconda.com/pkgs/main
  - https://repo.anaconda.com/pkgs/r
  - conda-forge
dependencies:
  - _libgcc_mutex=0.1=main
  - _openmp_mutex=5.1=1_gnu
  - attrs=21.4.0=pyhd3eb1b0_0
  - ca-certificates=2025.2.25=h06a4308_0
  - certifi=2021.5.30=py36h06a4308_0
  - importlib-metadata=4.8.1=py36h06a4308_0
  - importlib_metadata=4.8.1=hd3eb1b0_0
  - iniconfig=1.1.1=pyhd3eb1b0_0
  - ld_impl_linux-64=2.40=h12ee557_0
  - libffi=3.3=he6710b0_2
  - libgcc-ng=11.2.0=h1234567_1
  - libgomp=11.2.0=h1234567_1
  - libstdcxx-ng=11.2.0=h1234567_1
  - more-itertools=8.12.0=pyhd3eb1b0_0
  - ncurses=6.4=h6a678d5_0
  - openssl=1.1.1w=h7f8727e_0
  - packaging=21.3=pyhd3eb1b0_0
  - pip=21.2.2=py36h06a4308_0
  - pluggy=0.13.1=py36h06a4308_0
  - py=1.11.0=pyhd3eb1b0_0
  - pyparsing=3.0.4=pyhd3eb1b0_0
  - pytest=6.2.4=py36h06a4308_2
  - python=3.6.13=h12debd9_1
  - readline=8.2=h5eee18b_0
  - setuptools=58.0.4=py36h06a4308_0
  - sqlite=3.45.3=h5eee18b_0
  - tk=8.6.14=h39e8969_0
  - toml=0.10.2=pyhd3eb1b0_0
  - typing_extensions=4.1.1=pyh06a4308_0
  - wheel=0.37.1=pyhd3eb1b0_0
  - xz=5.6.4=h5eee18b_1
  - zipp=3.6.0=pyhd3eb1b0_0
  - zlib=1.2.13=h5eee18b_1
  - pip:
      - appdirs==1.4.4
      - args==0.1.0
      - astor==0.8.1
      - clint==0.5.1
      - rply==0.7.8
prefix: /opt/conda/envs/hy

tests/test_bin.py::test_bin_hy_byte_compile[hy
tests/test_bin.py::test_bin_hy_stdin tests/test_bin.py::test_bin_hy_icmd_and_spy
tests/test_bin.py::test_bin_hy tests/test_bin.py::test_bin_hy_stdin_multiline tests/test_bin.py::test_bin_hy_stdin_comments tests/test_bin.py::test_bin_hy_stdin_assignment tests/test_bin.py::test_bin_hy_stdin_as_arrow tests/test_bin.py::test_bin_hy_stdin_error_underline_alignment tests/test_bin.py::test_bin_hy_stdin_except_do tests/test_bin.py::test_bin_hy_stdin_hy_repr tests/test_bin.py::test_bin_hy_cmd tests/test_bin.py::test_bin_hy_icmd tests/test_bin.py::test_bin_hy_icmd_file tests/test_bin.py::test_bin_hy_missing_file tests/test_bin.py::test_bin_hy_file_with_args tests/test_bin.py::test_bin_hyc tests/test_bin.py::test_bin_hyc_missing_file tests/test_bin.py::test_hy2py tests/test_bin.py::test_bin_hy_builtins tests/test_bin.py::test_bin_hy_main tests/test_bin.py::test_bin_hy_main_args tests/test_bin.py::test_bin_hy_main_exitvalue tests/test_bin.py::test_bin_hy_no_main tests/test_bin.py::test_bin_hy_module_main tests/test_bin.py::test_bin_hy_module_main_args tests/test_bin.py::test_bin_hy_module_main_exitvalue tests/test_bin.py::test_bin_hy_module_no_main
NEWS hy/importer.py
NEWS hy/importer.py