Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Class converted to invalid code #51

Open
nedbat opened this issue Jan 31, 2021 · 2 comments
Open

Class converted to invalid code #51

nedbat opened this issue Jan 31, 2021 · 2 comments

Comments

@nedbat
Copy link

nedbat commented Jan 31, 2021

One of my test files (https://github.com/nedbat/coveragepy/blob/coverage-5.4/tests/test_testing.py) was converted into invalid code. I don't know what it is about that file that caused it, though it is a bit twisty: it's a test of test assert helper methods.

Here is a stripped-down file that shows the same behavior:

import pytest

from coverage.backunittest import TestCase

class TestingTest(TestCase):
    """Tests of helper methods on `backunittest.TestCase`."""

    def test_assert_count_equal(self):
        self.assertCountEqual(set(), set())
        with self.assertRaises(AssertionError):
            self.assertCountEqual({1,2,3}, set())
        with self.assertRaises(AssertionError):
            self.assertCountEqual({1,2,3}, {4,5,6})

Running unittest2pytest -w test_testing.py, the file becomes:

import pytest

from coverage.backunittest import TestCase
"""Tests of helper methods on `backunittest.TestCase`."""
deftest_assert_count_equal(self):
    self.assertCountEqual(set(), set())
    with pytest.raises(AssertionError):
        self.assertCountEqual({1,2,3}, set())
        withpytest.raises(AssertionError):
        self.assertCountEqual({1,2,3}, {4,5,6})
@nedbat
Copy link
Author

nedbat commented Jan 31, 2021

It also changed this file:

from coverage.backunittest import TestCase
from coverage.backward import iitems, binary_bytes, bytes_to_ints

class BackwardTest(TestCase):
    """Tests of things from backward.py."""

    def test_iitems(self):
        d = {'a': 1, 'b': 2, 'c': 3}
        items = [('a', 1), ('b', 2), ('c', 3)]
        self.assertCountEqual(list(iitems(d)), items)

    def test_binary_bytes(self):
        byte_values = [0, 255, 17, 23, 42, 57]
        bb = binary_bytes(byte_values)
        self.assertEqual(len(bb), len(byte_values))
        self.assertEqual(byte_values, list(bytes_to_ints(bb)))

to:

from coverage.backunittest import TestCase
from coverage.backward import iitems, binary_bytes, bytes_to_ints
"""Tests of things from backward.py."""
deftest_iitems(self):
    d = {'a': 1, 'b': 2, 'c': 3}
    items = [('a', 1), ('b', 2), ('c', 3)]
    self.assertCountEqual(list(iitems(d)), items)

    def test_binary_bytes(self):
    byte_values = [0, 255, 17, 23, 42, 57]
    bb = binary_bytes(byte_values)
    assert len(bb) == len(byte_values)
    assert byte_values == list(bytes_to_ints(bb))

nedbat added a commit to nedbat/coveragepy that referenced this issue Jan 31, 2021
unittest2pytest created syntax errors, reported here:
pytest-dev/unittest2pytest#51

This commit fixes them back.
nedbat added a commit to nedbat/coveragepy that referenced this issue Jan 31, 2021
unittest2pytest created syntax errors, reported here:
pytest-dev/unittest2pytest#51

This commit fixes them back.
@spookylukey
Copy link

I also noticed this. Several issues:

  • deftest_xxx instead of def test_xxx
  • self parameter wasn't removed
  • all comments got stripped

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

No branches or pull requests

2 participants