Comment 4 for bug 1315129

Revision history for this message
Marc Abramowitz (msabramo) wrote : Re: [Bug 1315129] Re: Trouble with intercepting/playing back submodule (sqlalchemy.exc)

Thanks! Yeah, I don't actually need to print out the class. That was just
for my little test program.

I hope to try out CaptureMock again soon with the real code I was using.
I'm trying to mock out a SQL Server database so that I can run the tests
quickly and without needing the database.

On Thu, May 8, 2014 at 12:27 PM, Geoff Bache <email address hidden> wrote:

> I checked in a fix for the double-import issue now.
>
> I haven't really thought of a good way to fix the class-printout issue
> yet, though I don't really know if it's important to you or was just
> illustrating the other issue.
>
> --
> You received this bug notification because you are subscribed to the bug
> report.
> https://bugs.launchpad.net/bugs/1315129
>
> Title:
> Trouble with intercepting/playing back submodule (sqlalchemy.exc)
>
> Status in CaptureMock:
> New
>
> Bug description:
> This might be a bug or it might be my misunderstanding of how things
> are supposed to work.
>
> I have this program and CaptureMock config:
>
> ```
> $ cat foobar.py
> import capturemock
>
> capturemock.process_startup()
>
>
> def foo():
> import sqlalchemy
> print(sqlalchemy.__version__)
> from sqlalchemy.exc import OperationalError
> print(OperationalError)
>
>
> foo()
>
> $cat config
> [python]
> intercepts = sqlalchemy,sqlalchemy.exc
> ```
>
> Then I attempt to record/replay to a file.
>
> ```
> $ cat /dev/null > foo.mock
>
> $ ls -l foo.mock
> -rw-r--r-- 1 marca staff 0 May 1 12:49 foo.mock
>
> $ CAPTUREMOCK_PROCESS_START=config CAPTUREMOCK_MODE=2
> CAPTUREMOCK_RECORD_FILE=foo.mock CAPTUREMOCK_REPLAY_FILE=foo.mock python
> foobar.py
> 0.8.6
> <class 'sqlalchemy.exc.OperationalError'>
>
> $ cat foo.mock
> <-PYT:import sqlalchemy
> <-PYT:sqlalchemy.__version__
> ->RET:'0.8.6'
> ```
>
> So here it recorded that I imported sqlalchemy and called
> sqlalchemy.__version__ but it didn't record my import of
> sqlalchemy.exc or usage of OperationalError... That doesn't seem right
> to me. Then when I run it again to replay what's in the file, it
> complains because it can't find the submodule sqlalchemy.exc:
>
> ```
> $ CAPTUREMOCK_PROCESS_START=config CAPTUREMOCK_MODE=2
> CAPTUREMOCK_RECORD_FILE=foo.mock CAPTUREMOCK_REPLAY_FILE=foo.mock python
> foobar.py
> 0.8.6
> Traceback (most recent call last):
> File "foobar.py", line 13, in <module>
> foo()
> File "foobar.py", line 9, in foo
> from sqlalchemy.exc import OperationalError
> ImportError: No module named exc
> ```
>
> Is this a bug or am I misnderstanding how things are supposed to work?
>
> To manage notifications about this bug go to:
> https://bugs.launchpad.net/capturemock/+bug/1315129/+subscriptions
>