OperatingSystem library Remove File keyword does not work in windows when using Mavem plugin

1,614 views
Skip to first unread message

Tatu aalto

unread,
May 2, 2012, 6:41:00 AM5/2/12
to robotframe...@googlegroups.com
Ugh

I have test library to the SUT, which function is to write some values to a csv file. In my test setup, I want to make sure that the previous tests csv are deleted from the target folder, before the new ones are created by the SUT. To delete the csv files, I use the operating system library Remove file keyword (Remove File    target${/}*.csv).

To run my test I use the the Maven plugin to run my test (mvn clean verify). Now when I run the test in a linux platform, all goes ok and csv files are deleted in the the test setup. If I execute the same test in a windows platform, I get an error:
<kw type="kw" timeout="" name="OperatingSystem.Remove File">
<doc>Removes a file with the given path.</doc>
<arguments>
<arg>target${/}*.csv</arg>
</arguments>
<msg timestamp="20120502 13:08:43.741" level="FAIL">OSError: unlink(): an unknown error occured: C:\yyy\model\csv\trunk\target\9999-801_20120320130000.csv</msg>
<msg timestamp="20120502 13:08:43.742" level="DEBUG">Traceback (most recent call last):
  File "C:\xxx\repository\org\robotframework\robotframework\2.7.1\robotframework-2.7.1.jar\Lib\robot\libraries\OperatingSystem$py.class", line 625, in remove_file</msg>
<status status="FAIL" starttime="20120502 13:08:43.735" endtime="20120502 13:08:43.742"/>
</kw>

If I set a timeout in the test and delete manually the csv files from the target directory, I do not get warning on the manual deletion about permissions or handles. Still one could suspect that SUT has some handle open to the csv file and for some reason the Robot fails to delete the csv file.

Has anyone had a similar problem and if yes, how did you fix it. Or is this a bug somewhere in the Robot and I should raise issue?

Pekka Klärck

unread,
May 3, 2012, 3:21:37 AM5/3/12
to aalto...@gmail.com, robotframe...@googlegroups.com
2012/5/2 Tatu aalto <aalto...@gmail.com>:
>
> Has anyone had a similar problem and if yes, how did you fix it. Or is this
> a bug somewhere in the Robot and I should raise issue?

I haven't heard about similar issues with Remove File keyword. The
error you got was `OSError: unlink(): an unknown error occured` which
is pretty weird. This keyword uses Python's `os.remove` method to
remove the file and that seems to fail for some reason. You could try
debugging the problem by creating a script that uses the same method
and running it without Robot. Since you seem to be using Jython, you
should also run the script with it.

Just submitting an issue about this won't help because I don't think
we could reproduce the problem. The keyword is pretty thoroughly
acceptance tested so clearly the problem does not occur in normal
situations. If you can create a simple standalone example
demonstrating the problem then we can obviously debug it further too.

Cheers,
.peke
--
Agile Tester/Developer/Consultant :: http://eliga.fi
Lead Developer of Robot Framework :: http://robotframework.org

Tatu Aalto

unread,
May 7, 2012, 12:52:11 PM5/7/12
to Pekka Klärck, robotframe...@googlegroups.com
Ugh

When taking the SUT out of the equation and using only Robot, I can not
procedure the problem. When using SUT, a "Run And Return Rc And Output"
keyword and use windows del-command, I get error message saying: Can not
delete x.csv file, the file is being used by another process. This
clearly indicates that this is some sort of windows problem.

Perhaps I can only test these in a *nix platform and perhaps only run
only one test at the time in windows.

-Tatu

Kevin O.

unread,
May 7, 2012, 11:03:26 PM5/7/12
to robotframe...@googlegroups.com, Pekka Klärck
If the DEL command elicits an error than maybe you can see exactly what process has it open.
Take a look at process explorer [1], which allows you to search for the process with an open file handle.  Could it be anti-virus?

Kevin

Tatu Aalto

unread,
May 8, 2012, 2:09:33 AM5/8/12
to korm...@gmail.com, robotframe...@googlegroups.com
Ugh

From Process Explorer I can see that the Java process that is running
the Maven plugin and that Java process is also running the SUT, is
responsible for keeping the csv file open.

It seems that this has something to do with the SUT, which should have
been closed between the test cases, because if I create files using
normal Robot keywords, deleting those files can be done without errors.
I will consult the developer and lets see how it goes on that front.

But I can reproduce the problem, with small trick. The test suite in the
attachment deletes all *.txt files from and c:\ and then creates a
c:\foobar.txt file. Now If I open c:\foobar.txt file to a MS excel and
run the "write file" test suite, I get the same error message:
"OSError: unlink(): an unknown error occured: c:\foobar.txt." It can be
also reproduced when running with jybot and one does not need to use the
Maven plugin. When the test suite is run by the pybot, the error text is
better: WindowsError: [Error 32] The process cannot access the file
because it is being used by another process: u'c:\\foobar.txt'.

The "unlink(): an unknown error" is somewhat confusing and one could
hope that the error text could be better. But if that relies enhancing
the Jython, then it is a long shot. But thank you all from help.

Tested in Windows 7 (64bit) and Robot Framework 2.7.1 (Python 2.7.2 on
win32) and Robot Framework 2.7.1 (Jython 2.5.2 on java1.7.0_03)

-Tatu
> --
> You received this message because you are subscribed to the Google
> Groups "robotframework-users" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/robotframework-users/-/V3epw3cBMw0J.
> To post to this group, send email to
> robotframe...@googlegroups.com.
> To unsubscribe from this group, send email to
> robotframework-u...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/robotframework-users?hl=en.
write_file.txt

Pekka Klärck

unread,
May 8, 2012, 4:10:26 AM5/8/12
to aalto...@gmail.com, korm...@gmail.com, robotframe...@googlegroups.com
2012/5/8 Tatu Aalto <aalto...@gmail.com>:
>
> But I can reproduce the problem, with small trick. The test suite in the
> attachment deletes all *.txt files from and c:\ and then creates a
> c:\foobar.txt file. Now If I open c:\foobar.txt file to a MS excel and run
> the "write file" test suite,  I get the same error message: "OSError:
> unlink(): an unknown error occured: c:\foobar.txt." It can be also
> reproduced when running with jybot and one does not need to use the Maven
> plugin. When the test suite is run by the pybot, the error text is better:
> WindowsError: [Error 32] The process cannot access the file because it is
> being used by another process: u'c:\\foobar.txt'.

You can also reproduce the same behavior by just opening a file with
Excel and trying to delete it e.g. using Windows Explorer. Excel opens
files in a mode that prevents others from deleting them.

> The "unlink(): an unknown error" is somewhat confusing and one could hope
> that the error text could be better. But if that relies enhancing the
> Jython, then it is a long shot. But thank you all from help.

That is definitely a bad error messages. It comes directly from Jython
so the problem should be fixed on that side. If you know any Java, you
can try to take a look at Jython source code to see could the error
message be enhanced somehow.

Anyway, your SUT not closing files properly is probably a bug and
finding it can be considered success. =)
Reply all
Reply to author
Forward
0 new messages