Merge pull request #6152 from grlee77/module_name_in_id
use __name__ attribute in the parametrize id for modules as well
This commit is contained in:
		
						commit
						245e1f10e5
					
				
							
								
								
									
										1
									
								
								AUTHORS
								
								
								
								
							
							
						
						
									
										1
									
								
								AUTHORS
								
								
								
								
							| 
						 | 
					@ -103,6 +103,7 @@ George Kussumoto
 | 
				
			||||||
Georgy Dyuldin
 | 
					Georgy Dyuldin
 | 
				
			||||||
Graham Horler
 | 
					Graham Horler
 | 
				
			||||||
Greg Price
 | 
					Greg Price
 | 
				
			||||||
 | 
					Gregory Lee
 | 
				
			||||||
Grig Gheorghiu
 | 
					Grig Gheorghiu
 | 
				
			||||||
Grigorii Eremeev (budulianin)
 | 
					Grigorii Eremeev (budulianin)
 | 
				
			||||||
Guido Wesdorp
 | 
					Guido Wesdorp
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1 @@
 | 
				
			||||||
 | 
					Now parametrization will use the ``__name__`` attribute of any object for the id, if present. Previously it would only use ``__name__`` for functions and classes.
 | 
				
			||||||
| 
						 | 
					@ -1162,7 +1162,8 @@ def _idval(val, argname, idx, idfn, item, config):
 | 
				
			||||||
        return ascii_escaped(val.pattern)
 | 
					        return ascii_escaped(val.pattern)
 | 
				
			||||||
    elif isinstance(val, enum.Enum):
 | 
					    elif isinstance(val, enum.Enum):
 | 
				
			||||||
        return str(val)
 | 
					        return str(val)
 | 
				
			||||||
    elif (inspect.isclass(val) or inspect.isfunction(val)) and hasattr(val, "__name__"):
 | 
					    elif hasattr(val, "__name__") and isinstance(val.__name__, str):
 | 
				
			||||||
 | 
					        # name of a class, function, module, etc.
 | 
				
			||||||
        return val.__name__
 | 
					        return val.__name__
 | 
				
			||||||
    return str(argname) + str(idx)
 | 
					    return str(argname) + str(idx)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -314,6 +314,21 @@ def test_keyword_option_parametrize(spec, testdir):
 | 
				
			||||||
    assert list(passed) == list(passed_result)
 | 
					    assert list(passed) == list(passed_result)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def test_parametrize_with_module(testdir):
 | 
				
			||||||
 | 
					    testdir.makepyfile(
 | 
				
			||||||
 | 
					        """
 | 
				
			||||||
 | 
					        import pytest
 | 
				
			||||||
 | 
					        @pytest.mark.parametrize("arg", [pytest,])
 | 
				
			||||||
 | 
					        def test_func(arg):
 | 
				
			||||||
 | 
					            pass
 | 
				
			||||||
 | 
					    """
 | 
				
			||||||
 | 
					    )
 | 
				
			||||||
 | 
					    rec = testdir.inline_run()
 | 
				
			||||||
 | 
					    passed, skipped, fail = rec.listoutcomes()
 | 
				
			||||||
 | 
					    expected_id = "test_func[" + pytest.__name__ + "]"
 | 
				
			||||||
 | 
					    assert passed[0].nodeid.split("::")[-1] == expected_id
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@pytest.mark.parametrize(
 | 
					@pytest.mark.parametrize(
 | 
				
			||||||
    "spec",
 | 
					    "spec",
 | 
				
			||||||
    [
 | 
					    [
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue