File tree Expand file tree Collapse file tree 2 files changed +25
-7
lines changed Expand file tree Collapse file tree 2 files changed +25
-7
lines changed Original file line number Diff line number Diff line change @@ -191,18 +191,22 @@ def getmod():
191
191
mod .append (x )
192
192
return mod [0 ]
193
193
194
+ x = modpath + ("." + attrname if attrname else "" )
195
+ repr_result = "<AliasModule {!r} for {!r}>" .format (modname , x )
196
+
194
197
class AliasModule (ModuleType ):
195
198
def __repr__ (self ):
196
- x = modpath
197
- if attrname :
198
- x += "." + attrname
199
- return "<AliasModule {!r} for {!r}>" .format (modname , x )
199
+ return repr_result
200
200
201
201
def __getattribute__ (self , name ):
202
202
try :
203
203
return getattr (getmod (), name )
204
204
except ImportError :
205
- return None
205
+ if modpath == "pytest" and attrname is None :
206
+ # hack for pylibs py.test
207
+ return None
208
+ else :
209
+ raise
206
210
207
211
def __setattr__ (self , name , value ):
208
212
setattr (getmod (), name , value )
Original file line number Diff line number Diff line change @@ -551,11 +551,25 @@ def test_aliasmodule_aliases_an_attribute():
551
551
assert not hasattr (am , "lqkje" )
552
552
553
553
554
- def test_aliasmodule_aliases_unimportable ():
554
+ def test_aliasmodule_aliases_unimportable_fails ():
555
555
am = apipkg .AliasModule ("mymod" , "qlwkejqlwe" , "main" )
556
556
r = repr (am )
557
557
assert "<AliasModule 'mymod' for 'qlwkejqlwe.main'>" == r
558
- assert am .qwe is None
558
+ # this would pass starting with apipkg 1.3 to work around a pytest bug
559
+ with pytest .raises (ImportError ):
560
+ am .qwe is None
561
+
562
+
563
+ def test_aliasmodule_pytest_autoreturn_none_for_hack (monkeypatch ):
564
+ def error (* k ):
565
+ raise ImportError (k )
566
+
567
+ monkeypatch .setattr (apipkg , "importobj" , error )
568
+ # apipkg 1.3 added this hack
569
+ am = apipkg .AliasModule ("mymod" , "pytest" )
570
+ r = repr (am )
571
+ assert "<AliasModule 'mymod' for 'pytest'>" == r
572
+ assert am .test is None
559
573
560
574
561
575
def test_aliasmodule_unicode ():
You can’t perform that action at this time.
0 commit comments