I have a few python unit test files. I'm copying all those files to a directory, which a file system watcher is listening and firing create event. I want to run those tests after all files are copied. The files that are being copied look something like:
unittest1.py
unittest2.py
unittestxyz.py
.
.
.
unittestRunner.py
unittestRunner.py file imports all other unittest files and starts all unit tests as a part of a suite. If I copy files to the watched directory, Created
event will fire that many times, in this case 4 times. So, somehow I want to 'wait' until all files are copied and then execute the unittestRunner
script. Files are being copied programmatically, and watcher is running as a part of a Windows Service.
I have 2, quite yuck solutions, and they may not even be solutions:
one is to specifically wait for unittestRunner.py
to be created:
watcher.Created += new FileSystemEventHandler((sender, eventArgs) =>
{
if (eventArgs.Name == "unittestRunner.py")
{
// Run Tests
}
});
but this won't work if runner file gets copied before any other file.
Other is to keep track the number of files that have to be copied somewhere in an xml file, and in the evnet handler check if the current number of copied files are the same:
watcher.Created += new FileSystemEventHandler((sender, eventArgs) =>
{
var totalCount = Directory.GetFiles(testFolder).Length;
var doc = new XmlDocument();
doc.Load("numberOfFilesToCopy.xml");
if (totalCount == doc.GetElementsByTagName("test-files")[0].ChildNodes.Count)
{
// Number is the same, all files copied, run tests
}
}
Is it somehow possible to wait for all the locks of all the files have been released before starting tests?