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

Single test not found when running pytest with "::" notation #125

Open
aleGpereira opened this issue Jul 7, 2021 · 1 comment
Open

Single test not found when running pytest with "::" notation #125

aleGpereira opened this issue Jul 7, 2021 · 1 comment

Comments

@aleGpereira
Copy link

By having the following project structure in a folder called parametized_bug:

.
├── Pipfile
├── Pipfile.lock
├── app.py
└── test
    └── test_app.py

where app.py:

def hello_world(arg1):
    """
    docstring
    """
    return f"Hello world {arg1}!"

and test_app.py:

from unittest import TestCase
from app import hello_world
from parameterized import parameterized

class TestApp(TestCase):

    @parameterized.expand(
        [('Mars'),('Jupiter')]
    )
    def test_hello_world(self, arg1):
        result = hello_world(arg1)
        self.assertEqual(result, f'Hello world {arg1}!')

If I run the following

python -m pytest test/test_app.py::TestApp                  
================================================================================================== test session starts ===================================================================================================
platform darwin -- Python 3.8.6, pytest-6.2.4, py-1.10.0, pluggy-0.13.1
rootdir: /Users/user/parametized_bug
collected 2 items                                                                                                                                                                                                        

test/test_app.py ..                                                                                                                                                                                                [100%]

=================================================================================================== 2 passed in 0.04s ====================================================================================================

But if I run it as this other way, it fails:

python -m pytest test/test_app.py::TestApp::test_hello_world
================================================================================================== test session starts ===================================================================================================
platform darwin -- Python 3.8.6, pytest-6.2.4, py-1.10.0, pluggy-0.13.1
rootdir: /Users/user/parametized_bug
collected 0 items                                                                                                                                                                                                        

================================================================================================= no tests ran in 0.03s ==================================================================================================
ERROR: not found: /Users/user/parametized_bug/test/test_app.py::TestApp::test_hello_world
(no name '/Users/user/parametized_bug/test/test_app.py::TestApp::test_hello_world' in any of [<Module test/test_app.py>])

If I change test_app.py to:

from unittest import TestCase
from app import hello_world

class TestApp(TestCase):

    def test_hello_world(self):
        arg1 = "Mars"
        result = hello_world(arg1)
        self.assertEqual(result, f'Hello world {arg1}!')

When I run it again, it works:

python -m pytest test/test_app.py::TestApp::test_hello_world
================================================================================================== test session starts ===================================================================================================
platform darwin -- Python 3.8.6, pytest-6.2.4, py-1.10.0, pluggy-0.13.1
rootdir: /Users/user/parametized_bug
collected 1 item                                                                                                                                                                                                         

test/test_app.py .                                                                                                                                                                                                 [100%]

=================================================================================================== 1 passed in 0.04s ====================================================================================================
@rohitnwork
Copy link

+1

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