Skip to content

panic when using pytestify on file that contains assertAlmostEqual #53

Description

@BBBmau

I get the following panics when I attempt to run pytestify that has a self.assertAlmostEqual from unittest:

Traceback (most recent call last):
  File "/home/batman/pyenv/versions/3.11.4/bin/pytestify", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/home/batman/pyenv/versions/3.11.4/lib/python3.11/site-packages/pytestify/_main.py", line 93, in main
    ret += _fix_path(filepath, args, notes)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/batman/pyenv/versions/3.11.4/lib/python3.11/site-packages/pytestify/_main.py", line 45, in _fix_path
    contents = rewrite_asserts(
               ^^^^^^^^^^^^^^^^
  File "/home/batman/pyenv/versions/3.11.4/lib/python3.11/site-packages/pytestify/fixes/asserts.py", line 370, in rewrite_asserts
    visitor = Visitor(tokens).visit_text(contents)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/batman/pyenv/versions/3.11.4/lib/python3.11/site-packages/pytestify/_ast_helpers.py", line 24, in visit_text
    self.visit(ast_parse(contents))
  File "/home/batman/pyenv/versions/3.11.4/lib/python3.11/ast.py", line 418, in visit
    return visitor(node)
           ^^^^^^^^^^^^^
  File "/home/batman/pyenv/versions/3.11.4/lib/python3.11/ast.py", line 426, in generic_visit
    self.visit(item)
  File "/home/batman/pyenv/versions/3.11.4/lib/python3.11/ast.py", line 418, in visit
    return visitor(node)
           ^^^^^^^^^^^^^
  File "/home/batman/pyenv/versions/3.11.4/lib/python3.11/ast.py", line 426, in generic_visit
    self.visit(item)
  File "/home/batman/pyenv/versions/3.11.4/lib/python3.11/ast.py", line 418, in visit
    return visitor(node)
           ^^^^^^^^^^^^^
  File "/home/batman/pyenv/versions/3.11.4/lib/python3.11/ast.py", line 426, in generic_visit
    self.visit(item)
  File "/home/batman/pyenv/versions/3.11.4/lib/python3.11/ast.py", line 418, in visit
    return visitor(node)
           ^^^^^^^^^^^^^
  File "/home/batman/pyenv/versions/3.11.4/lib/python3.11/ast.py", line 426, in generic_visit
    self.visit(item)
  File "/home/batman/pyenv/versions/3.11.4/lib/python3.11/ast.py", line 418, in visit
    return visitor(node)
           ^^^^^^^^^^^^^
  File "/home/batman/pyenv/versions/3.11.4/lib/python3.11/ast.py", line 428, in generic_visit
    self.visit(value)
  File "/home/batman/pyenv/versions/3.11.4/lib/python3.11/ast.py", line 418, in visit
    return visitor(node)
           ^^^^^^^^^^^^^
  File "/home/batman/pyenv/versions/3.11.4/lib/python3.11/site-packages/pytestify/fixes/asserts.py", line 174, in visit_Call
    kwargs[arg] = const.value  # type: ignore
                  ^^^^^^^^^^^
AttributeError: 'Name' object has no attribute 'value'

Forcing some manual changes in order for pytestify to complete the unittest -> pytestify conversion

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions