Skip to content

Fix some minor annoyances in Python tests#9132

Merged
greglandrum merged 5 commits intordkit:masterfrom
ricrogz:fix_py_tests_annoyances
Mar 6, 2026
Merged

Fix some minor annoyances in Python tests#9132
greglandrum merged 5 commits intordkit:masterfrom
ricrogz:fix_py_tests_annoyances

Conversation

@ricrogz
Copy link
Copy Markdown
Contributor

@ricrogz ricrogz commented Feb 25, 2026

I usually work on a Qt-based out-of-tree installation, and this patch addresses some issues in Python tests I have been ignoring for a (long) while:

  • The github4823 test is configured to run in-tree, and fails due to a rdkit import error when using an out-of-tree installation with RDK_INSTALL_INTREE disabled and RDK_INSTALL_PYTHON_TESTS enabled.

- UnitTestDraw.py::_testMolToFile() and UnitTestDraw.py::_testMolToImage() were not being run due to the test names being prefixed with an underscore. I renamed them and skipped them when Cairo is not available, since they both require MolToImage() at some point. MolToImage() is not available on Qt builds due to Cairo/Qt incompatibility. Whoops, these aren't meant to be tests, they are functions used by other tests...

  • PandasTools.py::testGithub1507() (both instances): As explained by the comment, SaveXlsxFromFrame() uses MolToImage() to generate PNG images that are embedded into the Xlsx file, and due to the incompatibility mentioned above, it won't work in Qt-based installations.

  • UnitTestPandasTools.py::test_github2380(): when run under ctest -R pythonSourceTests, this test fails in a Qt installation due to a test-test interaction with Chem/Draw/UnitTestIPython.py: when running pythonSourceTests,
    Chem/Draw/UnitTestIPython.py runs before UnitTestPandasTools.py::test_github2380(). It imports IPythonConsole, which sets up the IPython renderer (which allows avoiding the Qt/Cairo incompatibility by doing Draw.MolsToGridImage = IPythonConsole.ShowMols and drawing SVGs instead of PNGs), and then uninstalls it as the test ends. Since tests are all run in the same process, when UnitTestPandasTools.py::test_github2380() runs, the from rdkit.Chem.Draw import IPythonConsole call does not set up the renderer because the IPythonConsole module is still loaded, so the init won't trigger again, but since the rendered was uninstalled, Draw.MolsToGridImage() has been restored to the default implementation, which uses MolToImage(), triggering the failure. My fix ensures that the IPython rendered is installed before PandasTools.FrameToGridImage() is called, and then cleans it up after it runs.

ricrogz added a commit to ricrogz/rdkit that referenced this pull request Mar 5, 2026
Copy link
Copy Markdown
Member

@greglandrum greglandrum left a comment

Choose a reason for hiding this comment

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

LGTM

@greglandrum greglandrum added Cleanup Code cleanup and refactoring infrastructure build infrastructure and the like labels Mar 6, 2026
@greglandrum greglandrum added this to the 2026_03_1 milestone Mar 6, 2026
@greglandrum greglandrum merged commit 5d19a66 into rdkit:master Mar 6, 2026
12 checks passed
@ricrogz ricrogz deleted the fix_py_tests_annoyances branch March 6, 2026 13:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Cleanup Code cleanup and refactoring infrastructure build infrastructure and the like

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants