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

@pkienzle pkienzle commented Jun 1, 2026

Copy link
Copy Markdown
Contributor

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 *Test*py, 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

pkienzle commented Jun 1, 2026

Copy link
Copy Markdown
Contributor Author

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

pkienzle commented Jun 1, 2026

Copy link
Copy Markdown
Contributor Author

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

pkienzle commented Jun 1, 2026

Copy link
Copy Markdown
Contributor Author

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.

@llimeht

llimeht commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

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.

That might be the recently added QT_QPA_PLATFORM: offscreen which should obviate the need for xvfb. If pytest-xvfb is installed, then pytest-qt will automatically use it too, so there are multiple paths that might fix this.

@krzywon krzywon left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You fixed the underlying issue, but we should either modify the existing issue or create a new one outlining the behavior I'm seeing below.

python -m pytest . from the base sasview directory allows all tests to run, but with 17 failures on my end, all within the test directory.

= 17 failed, 747 passed, 5 skipped, 29 xfailed, 21 warnings in 204.14s (0:03:24) =

Running the sascalc tests separately (python -m pytest ./test) and they all pass suggesting the GUI tests are changing class variables before the calc tests can run. The exact cause will need more investigation.

= 189 passed, 2 skipped in 39.26s =

Failures from the global run:

test/sascalculator/utest_sas_gen.py::sas_gen_test::test_calculator_elements FAILED [ 78%]
test/sascalculator/utest_sas_gen.py::sas_gen_test::test_debye_impl FAILED [ 78%]
test/sascalculator/utest_sas_gen.py::sas_gen_test::test_vtkreader FAILED [ 79%]
test/sasinvariant/LinearTest.py::TestLinearFit::test_fit_covariance_fallback_on_linalg_failure FAILED [ 89%]
test/size_distribution/MaxEntTest.py::test_noRes FAILED [ 94%]
test/system/utest_resources.py::TestRecorded::test_extract_resource[_as_str] FAILED [ 97%]
test/system/utest_resources.py::TestRecorded::test_extract_resource[_as_path] FAILED [ 97%]
test/system/utest_resources.py::TestRecorded::test_extract_resource_tree[_as_str] FAILED [ 97%]
test/system/utest_resources.py::TestRecorded::test_extract_resource_tree[_as_path] FAILED [ 97%]
test/system/utest_resources.py::TestAdjacent::test_path_to_resource[_as_str] FAILED [ 97%]
test/system/utest_resources.py::TestAdjacent::test_path_to_resource[_as_path] FAILED [ 97%]
test/system/utest_resources.py::TestAdjacent::test_resource[_as_str] FAILED [ 98%]
test/system/utest_resources.py::TestAdjacent::test_resource[_as_path] FAILED [ 98%]
test/system/utest_resources.py::TestAdjacent::test_extract_resource[_as_str] FAILED [ 98%]
test/system/utest_resources.py::TestAdjacent::test_extract_resource[_as_path] FAILED [ 98%]
test/system/utest_resources.py::TestAdjacent::test_extract_resource_tree[_as_str] FAILED [ 98%]
test/system/utest_resources.py::TestAdjacent::test_extract_resource_tree[_as_path] FAILED [ 98%]

@llimeht

llimeht commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

The tests in test/system/utest_resources.py all pass when run on their own as either python -m pytest test/system/utest_resources.py or even python -m pytest test. They fail if the qtgui tests are run, however.

The cause appears to be somewhere within the logging setup that is inserted either by sasview, a qtgui test not cleaning up after itself properly, or pytest-qt itself. The tests fail Qt event loop exceptions after the actual test code has run.

TypeError: 'PySide6.QtWidgets.QTextEdit.insertPlainText' called with wrong argument types:
  PySide6.QtWidgets.QTextEdit.insertPlainText(str, LogRecord)
Supported signatures:
  PySide6.QtWidgets.QTextEdit.insertPlainText(text: str, /)

(obviously there's no actual Qt code involved in utest_resources.py, so this is coming from external config)

Excluding src/sas/qtgui/Utilities/UnitTesting/SasviewLoggerTest.py from the test run lets them pass (python -m pytest src/sas/qtgui/ test/system/utest_resources.py --ignore src/sas/qtgui/Utilities/UnitTesting/SasviewLoggerTest.py)

@krzywon krzywon requested a review from butlerpd June 16, 2026 13:34
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

3 participants