Skip to content

Allow pytest from project base directory#3974

Open
pkienzle wants to merge 3 commits into
mainfrom
3892-pytest-errors
Open

Allow pytest from project base directory#3974
pkienzle wants to merge 3 commits into
mainfrom
3892-pytest-errors

Conversation

@pkienzle
Copy link
Copy Markdown
Contributor

@pkienzle pkienzle commented Jun 1, 2026

Description

Allows pytest to run from the project base directory.

The unused sas.sascalc.simulations and sas.sascalc.realspace packages are not scanned for tests.

Fixes the glob pattern to look for files with "test" or "Test" in their name. The previous version was looking for "Testpy", which wasn't finding the utest files in the test directory on case sensitive filesystems. Instead, a second "u*py" glob pattern was introduced to find these tests, but that picks up non-test files such as "util.py" and "urls.py".

Fixes #3892

How Has This Been Tested?

Run "pytest" from the base directory of the project and check that it includes both "Test" files from qtgui and "utest*" files from the test subdirectory. Verify that there are no errors from the tests.

Review Checklist:

[if using the editor, use [x] in place of [ ] to check a box]

Documentation (check at least one)

  • There is nothing that needs documenting
  • Documentation changes are in this PR
  • There is an issue open for the documentation (link?)

Installers

  • There is a chance this will affect the installers, if so
    • Windows installer (GH artifact) has been tested (installed and worked)
    • MacOSX installer (GH artifact) has been tested (installed and worked)
    • Wheels installer (GH artifact) has been tested (installed and worked)

Licensing (untick if necessary)

  • The introduced changes comply with SasView license (BSD 3-Clause)

@pkienzle
Copy link
Copy Markdown
Contributor Author

pkienzle commented Jun 1, 2026

Note that the tests for "sas/docs/index.html" etc. in "test/system/utest_resources.py" are failing for me, but these tests also fail when using "pytest -s test" and "(cd test && pytest)", so it is outside the scope of this PR.

I tried both with an edittable install "uv pip install -e ." which leaves sas.__file__ in src/sas/__init__.py and with a non-edittable install "uv pip isntall ." which puts sas.__file__ in .venv/lib/python3.13/site-packages/sas/__init__.py. In both cases .venv/lib/python3.13/site-packages/sas/docs/index.html exists.

@pkienzle
Copy link
Copy Markdown
Contributor Author

pkienzle commented Jun 1, 2026

On the linux CI environment the GUI test is executed using xvfb-run.

# Ensure all test running dependencies are installed (https://pytest-qt.readthedocs.io/en/latest/troubleshooting.html)
sudo apt install -y libxkbcommon-x11-0 libxcb-icccm4 libxcb-image0 libxcb-keysyms1 libxcb-randr0 libxcb-render-util0 libxcb-xinerama0 libxcb-xfixes0 x11-utils
/sbin/start-stop-daemon --start --quiet --pidfile /tmp/custom_xvfb_99.pid --make-pidfile --background --exec /usr/bin/Xvfb -- :99 -screen 0 1920x1200x24 -ac +extension GLX
# Run the UI generation routine (with force recreate enabled)
python src/sas/qtgui/convertUI.py -f
# Suppress SIGSEGV from the tests until they can be fixed
retval=0
xvfb-run -a --server-args="-screen 0 1600x900x24" python -m pytest -rsx -v src/sas/qtgui/ || retval=$?
if [ $retval -eq 139 ]; then echo "WARNING: Python interpreter exited with Segmentation Fault. This normally indicates that Qt objects were not correctly deleted. This error is currently suppressed in SasView's test suite."; retval=0; fi
exit $retval

When I run the tests on linux with remote ssh login I did not set up xvfb but still the Qt tests ran to completion. I don't know if that means that the tests that render to the screen are silently ignored in my environment, or if the xvfb environment is not required for the test.

I don't see anything in pyproject.toml that is setting up xvfb.

@pkienzle
Copy link
Copy Markdown
Contributor Author

pkienzle commented Jun 1, 2026

I didn't see errors from docs/sphinx-docs/source-temp/user/models/src/ reported in #3892

Given that docs is not in the set of test paths listed in pyproject.toml they should not appear. There are no instances of >>> test code in src or in docs so there is no need to include doctests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Pytest throws when running tests against the base sasview directory

1 participant