the rename bug

4 views
Skip to first unread message

Olof Bjarnason

unread,
May 15, 2012, 1:04:45 AM5/15/12
to pytd...@googlegroups.com
Hi list!

I've discovered why renamed a .py file, which a test_some.py file is dependent upon, doesn't break the test.

Typical example: rename pytddmon.py while pytddmon is running on its own tests. All tests are dependent on pytddmon.py (through import pytddmon statements), but renaming pytddmon.py to strange.py DOES NOT BREAK THE TESTS.

While in some older versions of pytddmon, the change isn't even detected, that is not the case with the new Monitor-based pytddmon. But still the tests does not break! So the rename is detected as a change, but 17/17 green tests.

It just bewildered med the other night, how that was possible at all. But then I got it: Python looks not only on .py files, but also on .pyc files! That is, if you rename pytddmon.py, Python doesn't find it. But it finds pytddmon.pyc instead.

This probably is a feature of Python, so that you can distribute your Python application without source code if you want to, and it will work seamlessly.

But it does pose a problem to pytddmon that I'd like to solve. Some ad-hoc thoughts:

1) pytddmon could physically *delete* all .pyc files for every .py file it finds. That solution seems brutal and I'm not fond at all in deleting files automagically, even though .pyc files are output files and not source files
2) maybe there is some flag to unittest and/or python that could disable this "run-.pycs-when-.py-not-found"-feature?
3) list might have some beautiful idea how to solve this.

Thoughts?

Olof Bjarnason

unread,
May 18, 2012, 5:25:00 PM5/18/12
to pytd...@googlegroups.com
I just discovered this thread on stackoverflow, the -B flag to python is new for me:

http://stackoverflow.com/questions/3503970/make-python-ignore-pyc-files

It might be a good way around the rename bug (just run pytddmon like this: python -B pytddmon.py), since it avoids .pyc files alltogether (what we want when running unit tests dynamically).

2012/5/15 Olof Bjarnason <olof.bj...@gmail.com>

Samuel Ytterbrink

unread,
May 19, 2012, 7:41:05 AM5/19/12
to pytd...@googlegroups.com
put it in the shebang if its possible?

2012/5/18 Olof Bjarnason <olof.bj...@gmail.com>



--
//Samuel Ytterbrink

Olof Bjarnason

unread,
May 19, 2012, 7:52:51 AM5/19/12
to pytd...@googlegroups.com
That's a cool idea!

However, I did a little investigation with the -B flag, and .pyc files keeps being created :(.

I think it might be that -B isn't "inherited" to multiprocessing process/Pool?


2012/5/19 Samuel Ytterbrink <nep...@gmail.com>

Olof Bjarnason

unread,
May 19, 2012, 8:21:08 AM5/19/12
to pytd...@googlegroups.com
I pragmatic approach, which is kind of ugly, would be to detect discrepancies between the .pyc files and .py filed.

Here how: Since a rename of a .py file will make the "images" (taken by Monitor) differ (some.py -> some2.py will leave a some.pyc behind), we could use that information to tell the user that pytddmon needs to be restarted. "Rename detected, you need to restart pytddmon".

I admit it's really ugly. But from a user perspective I think it's better than being "left in the dark".

BTW - how does the .pyc mechanism work in Jython / IronPython? Maybe there are no .pyc files (cross my fingers)?

2012/5/19 Olof Bjarnason <olof.bj...@gmail.com>
Reply all
Reply to author
Forward
0 new messages