Behat stuck after a failed install

Behat stuck after a failed install

by Davo Smith -
Number of replies: 4
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

I was just wondering if anyone else had been hit by this problem and if they had a sensible solution to it?

I've had a few cases where the install has failed when initialising behat tests (in the latest example a block plugin had a couple of junk files inside it, so the directory was not removed when I switched branches, so there was an error due to the lack of version.php in the directory).

This can lead to a situation where the database partially exists, but there is no 'behattest' field created in the config table.

Therefore Moodle refuses to believe this is a behat site - it won't let me run any tests or drop the database and re-initialise it.

Even adding the missing field to the config table does not work, as the config values are all cached (and purging the caches purges the main site cache, not the behat site cache).

The best solution I've found, is to comment out the 'is_test_site()' check, drop + rebuild the behat site (after fixing the initial error) and then put the check back in place.

Does anyone have a better solution than this?

Average of ratings: -
In reply to Davo Smith

Re: Behat stuck after a failed install

by Jessica Gramp -
Picture of Moodle HQ Picture of Plugin developers

Hi Davo,


I'm having the same issue. Where do I comment out is_test_site? I can't find this.


Thanks,


Jess

In reply to Jessica Gramp

Re: Behat stuck after a failed install

by Davo Smith -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

Usually your IDE can find functions very quickly (for example, in PHPStorm I hit Ctrl+Alt+Shift+N and type 'is_test_site' and it takes me to the definition, holding Ctrl and clicking on the name of the function takes me to everywhere it is used).

In this case, lib/behat/classes/util.php - function test_environment_problem(), approx line 214, comment out the 'This is not a behat test site!' error (but be very certain you are doing the right thing - this will allow you to drop a real site, if you call 'drop' on the wrong site).

In reply to Davo Smith

Re: Behat stuck after a failed install

by Mark Johnson -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

I usually find the solution to this case (without messing with code) is to manually drop all the database tables with the behat prefix and delete the contents of the behat dataroot folder.  After that, the behat init.php script should work again.

(Perhaps util.php should have a --fix-broken option which does this).

Average of ratings: Useful (3)
In reply to Mark Johnson

Re: Behat stuck after a failed install

by Jessica Gramp -
Picture of Moodle HQ Picture of Plugin developers

Thanks Mark. 

I think I managed to find the code I need to comment out in my version (Moodle 3.1).

Thanks Davo for pointing me in the right direction. I don't have the 'is_test_site()' function in my util.php, but I have commented out the following on line 110 and it's now dropping my behat tables for me when I run admin/tool/behat/cli/util.php --drop:

if ($status) {

    exit ($status);

}

Thanks both for getting back to me so quickly.