Move _from_module override to pre-existsing DocTestFinder subclass
This commit is contained in:
		
							parent
							
								
									d4fb6ac9f7
								
							
						
					
					
						commit
						ebd571bb18
					
				| 
						 | 
					@ -537,14 +537,11 @@ class DoctestModule(Module):
 | 
				
			||||||
                        tests, obj, name, module, source_lines, globs, seen
 | 
					                        tests, obj, name, module, source_lines, globs, seen
 | 
				
			||||||
                    )
 | 
					                    )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        class CachedPropertyAwareDocTestFinder(MockAwareDocTestFinder):
 | 
					 | 
				
			||||||
            def _from_module(self, module, object):
 | 
					            def _from_module(self, module, object):
 | 
				
			||||||
                """Doctest code does not take into account `@cached_property`,
 | 
					                """`cached_property` objects will are never considered a part
 | 
				
			||||||
                this is a hackish way to fix it. https://github.com/python/cpython/issues/107995
 | 
					                of the 'current module'. As such they are skipped by doctest.
 | 
				
			||||||
 | 
					                Here we override `_from_module` to check the underlying
 | 
				
			||||||
                Wrap Doctest finder so that when it calls `_from_module` for
 | 
					                function instead. https://github.com/python/cpython/issues/107995
 | 
				
			||||||
                a cached_property it uses the underlying function instead of the
 | 
					 | 
				
			||||||
                wrapped cached_property object.
 | 
					 | 
				
			||||||
                """
 | 
					                """
 | 
				
			||||||
                if isinstance(object, functools.cached_property):
 | 
					                if isinstance(object, functools.cached_property):
 | 
				
			||||||
                    object = object.func
 | 
					                    object = object.func
 | 
				
			||||||
| 
						 | 
					@ -571,7 +568,7 @@ class DoctestModule(Module):
 | 
				
			||||||
                else:
 | 
					                else:
 | 
				
			||||||
                    raise
 | 
					                    raise
 | 
				
			||||||
        # Uses internal doctest module parsing mechanism.
 | 
					        # Uses internal doctest module parsing mechanism.
 | 
				
			||||||
        finder = CachedPropertyAwareDocTestFinder()
 | 
					        finder = MockAwareDocTestFinder()
 | 
				
			||||||
        optionflags = get_optionflags(self)
 | 
					        optionflags = get_optionflags(self)
 | 
				
			||||||
        runner = _get_runner(
 | 
					        runner = _get_runner(
 | 
				
			||||||
            verbose=False,
 | 
					            verbose=False,
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue