Skip to content

Commit

Permalink
python3Packages.pywebview: build fix for tests
Browse files Browse the repository at this point in the history
Fixes #353686

Basically the *tests/run.sh* used upstream has a few rough edges and this replaces it with a smoother version.
An issue was also opened on the upstream project to maybe get this smoothed out generally.

Story time for those who are curious.
Basically upstream uses this as a script to call for the CI pipeline where [the builds seem to run smoothly in appveyor](https://ci.appveyor.com/project/r0x0r/pywebview/builds/50791017).
However the general structure of the script iterates over the files, which in earlier versions had been done by collecting the list of tests via pytest itself, which replaced the earliest implementation which was a file hard-coding all the tests to run.
The latter had the benefit of being able to disable tests by commenting them out on our end, however the new version, at least for our purpose, is just a more complicated version of running pytest against the entire thing.
We can't just use plain pytest however (which'd presumably be supported by nixpkgs infra already) because we still need to shove the Qt and xvfb-run shims in between.
So with running pytest as a single command we are now (with this commit) able to specifically disable tests that we know to be flakey using regular pytest means.
With the Qt wrapper function passing extra args to *makeWrapper* we can use the extra flags to pass everything we need, and with the env invocation we avoid polluting the build environment so that the *checkPhase* itself doesn't change the output.

Now on to the actual failing tests, apparently those happened to be related to relative paths which use an internal HTTP server to be served (for absolute paths this is optional), and getting rid of the cwd shenanigans which were required by the upstream version of the script (since it globbed on the current directory) means that somehow pytest now runs these tests without changing directory in a subprocess so the asset used for testing is properly accessible (before this change one could "fix" the tests by changing to an absolute path in the tests).

Signed-off-by: benaryorg <binary@benary.org>
  • Loading branch information
benaryorg committed Nov 9, 2024
1 parent 7acb302 commit bdfa0f0
Showing 1 changed file with 10 additions and 14 deletions.
24 changes: 10 additions & 14 deletions pkgs/development/python-modules/pywebview/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -50,21 +50,17 @@ buildPythonPackage rec {
];

checkPhase = ''
# Cannot create directory /homeless-shelter/.... Error: FILE_ERROR_ACCESS_DENIED
export HOME=$TMPDIR
# QStandardPaths: XDG_RUNTIME_DIR not set
export XDG_RUNTIME_DIR=$HOME/xdg-runtime-dir
# a Qt wrapper is required to run the Qt backend
# since the upstream script does not have a way to disable tests individually pytest is used directly instead
makeQtWrapper "$(command -v pytest)" tests/run.sh \
--set PYWEBVIEW_LOG debug \
--add-flags "--deselect tests/test_js_api.py::test_concurrent"
pushd tests
substituteInPlace run.sh \
--replace "PYTHONPATH=.." "PYTHONPATH=$PYTHONPATH" \
--replace "pywebviewtest test_js_api.py::test_concurrent ''${PYTEST_OPTIONS}" "# skip flaky test_js_api.py::test_concurrent"
patchShebangs run.sh
wrapQtApp run.sh
xvfb-run -s '-screen 0 800x600x24' ./run.sh
popd
# HOME and XDG directories are required for the tests
env \
HOME=$TMPDIR \
XDG_RUNTIME_DIR=$TMPDIR/xdg-runtime-dir \
xvfb-run -s '-screen 0 800x600x24' tests/run.sh
'';

pythonImportsCheck = [ "webview" ];
Expand Down

0 comments on commit bdfa0f0

Please sign in to comment.