Skip to content

Conversation

Copy link

Copilot AI commented Dec 13, 2025

Applied ruff check --select=PT --fix --unsafe-fixes to modernize test assertions from unittest to pytest style.

Changes

  • Converted 278 PT009 violations: unittest assertions → pytest assertions

    • self.assertEqual(a, b)assert a == b
    • self.assertIn(a, b)assert a in b
    • self.assertRegex(text, pattern)assert re.search(pattern, text)
  • Converted 19 PT027 violations: unittest raises → pytest context managers

    • self.assertRaises(ValueError, func, args)with pytest.raises(ValueError): func(args)
  • Configuration: Removed PT009 and PT027 from ignore list in pyproject.toml

  • Imports: Added pytest to test files and re to test_cloud.py (required for converted assertRegex calls)

4 PT011 warnings remain (pytest.raises too broad) - these are not auto-fixable and require manual match parameters.

Original prompt

ruff check --select=PT --fix --unsafe-fixes


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI changed the title [WIP] Run ruff check with fixes and unsafe options Apply ruff PT fixes: Convert unittest assertions to pytest style Dec 13, 2025
Copilot AI requested a review from cclauss December 13, 2025 18:09
@cclauss
Copy link
Contributor

cclauss commented Dec 13, 2025

pytest discovers and passes 181 tests.
unittest discovers and passes 131 tests.


✓ Setup completed successfully!
✓ Solr test server is ready
→ Running unit test suite...
============================= test session starts ==============================
platform linux -- Python 3.14.2, pytest-9.0.2, pluggy-1.6.0
rootdir: /home/runner/work/pysolr/pysolr
configfile: pyproject.toml
collected 183 items
tests/test_admin.py ..............                                       [  7%]
tests/test_client.py ................................................... [ 35%]
............                                                             [ 42%]
tests/test_cloud.py .................................................... [ 70%]
.......................s............................s.                   [100%]
======================= 181 passed, 2 skipped in 29.22s ========================

..........................s............................s...........................................................................
----------------------------------------------------------------------
Ran 131 tests in 20.750s
OK (skipped=2)

@cclauss cclauss changed the title Apply ruff PT fixes: Convert unittest assertions to pytest style Upgrade from unittest to pytest Dec 13, 2025
@DhavalGojiya
Copy link
Contributor

DhavalGojiya commented Dec 14, 2025

pytest discovers and passes 181 tests.
unittest discovers and passes 131 tests.

The correct number is 131 reported by unittest.
I think the issue is inside tests/test_cloud.py.

PyTest runs
tests/test_admin.py --> 14 Test Case
tests/test_client.py --> 56 Test Case
+
tests/test_cloud.py:
( import statement from .test_client import SolrTestCase) ( 56 Test Case again)
+
( class SolrCloudTestCase(SolrTestCase): ) + Again 56
+inside SolrCloudTestCase

@DhavalGojiya
Copy link
Contributor

DhavalGojiya commented Dec 14, 2025

unittest discovers and passes 131 tests.

UnitTest is reading only tests/__init__.py file.
And we import our all test modules there so at the end there is total 131 test case inside tests/__init__.py and this is correct.
Because each python import override last imported property.
So here we don't see same class SolrTestCase two times.

If you run each module test case explicitly even after using unittest:
uv run pytest -m unittest tests test_admin
uv run python -m unittest tests.test_client
uv run python -m unittest tests.test_cloud

You will see again 181 Test cases if you count all test cases from above commands output.
The uv run python -m unittest tests.test_cloud run class SolrTestCase also actual SolrCloudTestCase

@DhavalGojiya
Copy link
Contributor

DhavalGojiya commented Dec 14, 2025

@cclauss
Can you try adding this inside tests/test_cloud.py

# Add this line to prevent pytest from collecting the imported class
SolrTestCase.__test__ = False

And if nothing runs inside test_cloud module then the second thing we want to do is

class SolrCloudTestCase(SolrTestCase):
    __test__ = True  # Explicitly enable for this class (Inheritance effect remove) 

Ref: pytest-doc

@cclauss cclauss force-pushed the copilot/run-ruff-check-and-fix branch from 7a73899 to 3be3ede Compare December 18, 2025 12:46
@cclauss cclauss marked this pull request as ready for review December 18, 2025 15:58
@cclauss cclauss marked this pull request as draft December 18, 2025 15:58
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.

3 participants