forked from mirrors/nixpkgs
pytest: new hook to delete pytest bytecode
In https://github.com/NixOS/nixpkgs/issues/139292 we found out that pytest leaves pytest-generated bytecode in install directory (as tests are ran after install). That bytecode is: - non-deterministic (was copied from cpython before cpython got support for deterministic bytecode) - unneeded after test run The change cleans bytecode up and provides a hook variable to avoid it if needed. Tested on `python39Packages.pytest-xdist` and `python27Packages.flaky` as: $ nix build -f. python39Packages.pytest-xdist $ nix build -f. python39Packages.pytest-xdist --rebuild $ nix build -f. python27Packages.flaky $ nix build -f. python27Packages.flaky --rebuild Closes: https://github.com/NixOS/nixpkgs/issues/139292
This commit is contained in:
parent
062a1496d6
commit
f0bb568b74
|
@ -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; {
|
||||
|
|
|
@ -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 = [
|
||||
|
|
|
@ -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 = [
|
||||
|
|
Loading…
Reference in a new issue