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

pytest_parametrize_plus incompatible with classes #63

Closed
gjoseph92 opened this issue Oct 25, 2019 · 3 comments
Closed

pytest_parametrize_plus incompatible with classes #63

gjoseph92 opened this issue Oct 25, 2019 · 3 comments

Comments

@gjoseph92
Copy link

# test.py
import pytest                                                                
from pytest_cases import fixture_ref, pytest_parametrize_plus                
                                                                             
                                                                             
@pytest.fixture                                                              
def foo():                                                                   
    return 1                                                                 
                                                                             
@pytest.fixture                                                              
def bar():                                                                   
    return 2                                                                 
                                                                             
                                                                             
@pytest_parametrize_plus("arg", [fixture_ref("foo"), fixture_ref("bar")])    
def test_thing(arg):                                                         
    print(arg)                                                               
                                                                             
class TestCase:                                                              
    @pytest.mark.parametrize("arg", [1, 2])                                  
    def test_thing_pytest(self, arg):                                        
        print(arg)                                                           
                                                                             
    @pytest_parametrize_plus("arg", [fixture_ref("foo"), fixture_ref("bar")])
    def test_thing_cases(self, arg):                                         
        print(arg)                                                           

This causes fixture 'self' not found on the TestCase class:

$ pytest test.py
================================================== test session starts =================================================== 
platform linux -- Python 3.7.3, pytest-5.2.2, py-1.8.0, pluggy-0.13.0                                                      
rootdir: /home/gabejoseph/experiments/pytest-cases                                                                         
plugins: cases-1.11.4                                                                                                      
collected 5 items                                                                                                          
                                                                                                                           
test.py ....E                                                                                                      [100%]  
                                                                                                                           
========================================================= ERRORS ========================================================= 
______________________________________ ERROR at setup of TestCase.test_thing_cases _______________________________________ 
file /home/gabejoseph/experiments/pytest-cases/test.py, line 23: source code not available                                 
E       fixture 'self' not found                                                                                           
>       available fixtures: bar, cache, capfd, capfdbinary, caplog, capsys, capsysbinary, doctest_namespace, foo, monkeypat
ch, pytestconfig, record_property, record_testsuite_property, record_xml_attribute, recwarn, test_thing_arg, test_thing_cas
es_arg, tmp_path, tmp_path_factory, tmpdir, tmpdir_factory                                                                 
>       use 'pytest --fixtures [testpath]' for help on them.                                                               
                                                                                                                           
/home/gabejoseph/experiments/pytest-cases/test.py:23                                                                       
==================================================== warnings summary ==================================================== 
/home/gabejoseph/.local/share/virtualenvs/pytest-cases-QHs3Ehpk/lib/python3.7/site-packages/pytest_cases/plugin.py:129     
  /home/gabejoseph/.local/share/virtualenvs/pytest-cases-QHs3Ehpk/lib/python3.7/site-packages/pytest_cases/plugin.py:129: U
serWarning: WARNING the new order is not taken into account !!                                                             
    warn("WARNING the new order is not taken into account !!")                                                             
                                                                                                                           
-- Docs: https://docs.pytest.org/en/latest/warnings.html                                                                   
========================================= 4 passed, 1 warnings, 1 error in 0.03s ========================================= 

Notice that with the test_thing_pytest function, normal pytest.mark.parametrize handles self just fine.

Pipfile:

[[source]]                     
name = "pypi"                  
url = "https://pypi.org/simple"
verify_ssl = true              
                               
[dev-packages]                 
                               
[packages]                     
pytest-cases = "==1.11.4"      
pytest = "==5.2.2"             
                               
[requires]                     
python_version = "3.7"
@smarie
Copy link
Owner

smarie commented Nov 5, 2019

Thanks for reporting this ! I'll have a look

@smarie smarie closed this as completed in bd2fae3 Nov 5, 2019
@smarie
Copy link
Owner

smarie commented Nov 5, 2019

Fixed in 1.11.5, it should be deployed in a few minutes. Thanks again for reporting !

@smarie
Copy link
Owner

smarie commented Nov 5, 2019

Bad luck : the travis CI system has global issues syncing with github, and in particular it can not run "tagged" builds, which I use for pypi releases.

https://travis-ci.org/help?anchor=top&page=https%3A%2F%2Ftravis-ci.org%2Faccount%2Frepositories

The release will be done when travis is fixed. Sorry for the delay :(

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