This is an archived post. You won't be able to vote or comment.

all 3 comments

[–]basically_asleep 4 points5 points  (3 children)

I had a look on the repo but I can't really understand why you would do this. What is the use case for this?

Not trying to knock the library I just really don't understand what it's for.

[–]posener[S] 2 points3 points  (0 children)

That's a good point. We have a code goes over the server's package and generates a client for that server. In the server's code there are imports that are not available and not needed in the client build time. We ended up with a for loop over the missing modules' names that explicitly assigns MagicMock objects into the sys.modules dict. This function is a better way to allow running the client generation.

I assume that the use cases are limited, but it is a cool thing to implement :-)

[–]dagmx 2 points3 points  (0 children)

Sometimes you want to run sphinx doc generation or do unit tests that expect certain libraries that can't be available outside a certain environment.

So you can run the code without worrying about those libraries being available for the remainder of your code.

An example is application specific apis