[tor-commits] [stem/master] Workaround for screwy RuntimeError related to mock causing imports

atagar at torproject.org atagar at torproject.org
Mon Jul 22 03:10:17 UTC 2013


commit 762b7239e4866ba1b98212259e9751723e0865df
Author: Damian Johnson <atagar at torproject.org>
Date:   Sat Jul 6 10:54:58 2013 -0700

    Workaround for screwy RuntimeError related to mock causing imports
    
    The following isn't used by this directly, but we're still importing it due
    to a screwy aspect of how mock works. If patched() results in an import that
    we haven't done before then we can fail with...
    
      ======================================================================
      ERROR: test_query_download
      ----------------------------------------------------------------------
      Traceback (most recent call last):
        File "/usr/local/lib/python2.7/dist-packages/mock.py", line 1201, in patched
          return func(*args, **keywargs)
        ...
        File "/home/atagar/Desktop/stem/stem/descriptor/__init__.py", line 156, in parse_file
          import stem.descriptor.networkstatus
      RuntimeError: cannot unmarshal code objects in restricted execution mode
    
    I've only seen this arise when running this test directly (without the rest
    of the unit tests, some of which import networkstatus on their own).
---
 test/unit/descriptor/remote.py |    7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/test/unit/descriptor/remote.py b/test/unit/descriptor/remote.py
index 9e8b5cc..079937b 100644
--- a/test/unit/descriptor/remote.py
+++ b/test/unit/descriptor/remote.py
@@ -10,6 +10,13 @@ import stem.descriptor.remote
 
 from mock import patch
 
+# The following isn't used by this directly, but we're still importing it due
+# to a screwy aspect of how mock works. If patched() results in an import that
+# we haven't done before then we can fail with a RuntimeError. In practice this
+# just arises if we run this unit test on its own.
+
+import stem.descriptor.networkstatus
+
 # Output from requesting moria1's descriptor from itself...
 # % curl http://128.31.0.39:9131/tor/server/fp/9695DFC35FFEB861329B9F1AB04C46397020CE31
 





More information about the tor-commits mailing list