diff --git a/pkgs/development/python-modules/pytest/4.nix b/pkgs/development/python-modules/pytest/4.nix index fd6d3507afb8..0a0ae571ba01 100644 --- a/pkgs/development/python-modules/pytest/4.nix +++ b/pkgs/development/python-modules/pytest/4.nix @@ -43,6 +43,19 @@ buildPythonPackage rec { } preDistPhases+=" pytestcachePhase" + + # pytest generates it's own bytecode files to improve assertion messages. + # These files similar to cpython's bytecode files but are never laoded + # by python interpreter directly. We remove them for a few reasons: + # - files are non-deterministic: https://github.com/NixOS/nixpkgs/issues/139292 + # (file headers are generatedt by pytest directly and contain timestamps) + # - files are not needed after tests are finished + pytestRemoveBytecodePhase () { + # suffix is defined at: + # https://github.com/pytest-dev/pytest/blob/4.6.11/src/_pytest/assertion/rewrite.py#L32-L47 + find $out -name "*-PYTEST.py[co]" -delete + } + preDistPhases+=" pytestRemoveBytecodePhase" ''; meta = with lib; { diff --git a/pkgs/development/python-modules/pytest/5.nix b/pkgs/development/python-modules/pytest/5.nix index b38c1a759fe3..8df7c02b1774 100644 --- a/pkgs/development/python-modules/pytest/5.nix +++ b/pkgs/development/python-modules/pytest/5.nix @@ -70,6 +70,19 @@ buildPythonPackage rec { find $out -name .pytest_cache -type d -exec rm -rf {} + } preDistPhases+=" pytestcachePhase" + + # pytest generates it's own bytecode files to improve assertion messages. + # These files similar to cpython's bytecode files but are never laoded + # by python interpreter directly. We remove them for a few reasons: + # - files are non-deterministic: https://github.com/NixOS/nixpkgs/issues/139292 + # (file headers are generatedt by pytest directly and contain timestamps) + # - files are not needed after tests are finished + pytestRemoveBytecodePhase () { + # suffix is defined at: + # https://github.com/pytest-dev/pytest/blob/5.4.3/src/_pytest/assertion/rewrite.py#L42-L45 + find $out -name "*-pytest-*.py[co]" -delete + } + preDistPhases+=" pytestRemoveBytecodePhase" ''; pythonImportsCheck = [ diff --git a/pkgs/development/python-modules/pytest/default.nix b/pkgs/development/python-modules/pytest/default.nix index f2438622f6a6..ac036936b991 100644 --- a/pkgs/development/python-modules/pytest/default.nix +++ b/pkgs/development/python-modules/pytest/default.nix @@ -82,6 +82,19 @@ buildPythonPackage rec { find $out -name .pytest_cache -type d -exec rm -rf {} + } preDistPhases+=" pytestcachePhase" + + # pytest generates it's own bytecode files to improve assertion messages. + # These files similar to cpython's bytecode files but are never laoded + # by python interpreter directly. We remove them for a few reasons: + # - files are non-deterministic: https://github.com/NixOS/nixpkgs/issues/139292 + # (file headers are generatedt by pytest directly and contain timestamps) + # - files are not needed after tests are finished + pytestRemoveBytecodePhase () { + # suffix is defined at: + # https://github.com/pytest-dev/pytest/blob/6.2.5/src/_pytest/assertion/rewrite.py#L51-L53 + find $out -name "*-pytest-*.py[co]" -delete + } + preDistPhases+=" pytestRemoveBytecodePhase" ''; pythonImportsCheck = [