Skip to content

GitLab

  • Menu
Projects Groups Snippets
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
  • Sign in / Register
  • erp5 erp5
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Merge requests 143
    • Merge requests 143
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Jobs
  • Commits
Collapse sidebar
  • nexedi
  • erp5erp5
  • Merge requests
  • !2161

Open
Created Sep 19, 2025 by Jérome Perrin@jeromeOwner
  • Report abuse
Report abuse

tests: stop using deprecated unittest.makeSuite

  • Overview 1
  • Commits 2
  • Pipelines 1
  • Changes 264

done with:

import libcst as cst
import sys

class RewriteMakeSuite(cst.CSTTransformer):
    def leave_Call(self, original_node: cst.Call, updated_node: cst.Call) -> cst.BaseExpression:
        func = updated_node.func
        if isinstance(func, cst.Attribute) and isinstance(func.value, cst.Name):
            if func.value.value == "unittest" and func.attr.value == "makeSuite":
                first_arg = updated_node.args[0]

                # check second argument
                if len(updated_node.args) > 1:
                    second = updated_node.args[1].value
                    if isinstance(second, cst.SimpleString):
                        val = second.evaluated_value
                        if val != "test":
                            print(f"ERROR: unexpected second argument {second.code!r} in {original_node.code!r}", file=sys.stderr)
                            return updated_node
                    else:
                        print(f"ERROR: non-string second argument in {original_node.code!r}", file=sys.stderr)
                        return updated_node

                # keep only first argument and remove comma
                new_args = [first_arg.with_changes(comma=None)]

                new_func = cst.Attribute(
                    value=cst.Attribute(
                        value=cst.Name("unittest"),
                        attr=cst.Name("defaultTestLoader"),
                    ),
                    attr=cst.Name("loadTestsFromTestCase"),
                )
                return updated_node.with_changes(func=new_func, args=new_args)
        return updated_node

if __name__ == "__main__":
    for path in sys.argv[1:]:
        src = open(path).read()
        mod = cst.parse_module(src)
        new_mod = mod.visit(RewriteMakeSuite())
        with open(path, "w") as f:
            f.write(new_mod.code)
Assignee
Assign to
Reviewer
Request review from
Time tracking
Source branch: fix/makeSuite
GitLab Nexedi Edition | About GitLab | About Nexedi | 沪ICP备2021021310号-2 | 沪ICP备2021021310号-7