the rename bug

Skip to first unread message

Olof Bjarnason

May 15, 2012, 1:04:45 AM5/15/12
Hi list!

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

Typical example: rename while pytddmon is running on its own tests. All tests are dependent on (through import pytddmon statements), but renaming to 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, 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 ""-feature?
3) list might have some beautiful idea how to solve this.


Olof Bjarnason

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

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

2012/5/15 Olof Bjarnason <>

Samuel Ytterbrink

May 19, 2012, 7:41:05 AM5/19/12
put it in the shebang if its possible?

2012/5/18 Olof Bjarnason <>

//Samuel Ytterbrink

Olof Bjarnason

May 19, 2012, 7:52:51 AM5/19/12
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 <>

Olof Bjarnason

May 19, 2012, 8:21:08 AM5/19/12
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 ( -> 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 <>
Reply all
Reply to author
0 new messages