DUNFERMLINE has a rich history as a royal burgh but not as a happy hunting ground for the SNP, so when the Nationalists captured the Holyrood seat in 2011 it was one of the shocks of the night.

This week the party has to defend it in a by-election and it looks a tall order. The two by-elections of recent months demonstrate just how difficult Thursday is going to be for Alex Salmond's flag-bearer, Shirley-Anne Somerville.

In June we had the contest in Aberdeen Donside, caused by the death of popular incumbent Brian Adam, who had built an impressive party machine in the north of the granite city and turned it into an SNP stronghold with a share of the vote in excess of 50%.

His anointed successor Mark McDonald resigned as a list MSP to fight the contest, didn't put a foot wrong, and still shed 13% of the party's share of the vote with a nine-point swing to Labour.

The SNP still won that contest with a couple of thousand votes to spare, but it highlighted how hard mid-term victories can be for the Government of the day. Fast-forward four months and the party faces a very different scenario in Dunfermline.

The party machine in West Fife does not compare, and instead of a by-election caused by the death of a well-respected sitting MSP this is a contest sparked by the resignation in disgrace of a serial wife-beater who the SNP had been forced to expel from the party. Despite his conviction and prison sentence, Bill Walker had to be virtually hounded from office, and Labour has not been shy in using this by repeating the mantra "Dunfermline deserves better".

The bookmakers have made Labour odds-on favourites in a two-horse race. The Liberal Democrats, who were once a political force in this town, are at 50/1 and everybody else, including the Conservative, is posted at 100/1.

So you might expect Ms ­Somerville to be somewhat ­downbeat. Not a bit of it. Feisty with a touch of steel would be nearer the mark. Her campaign has two main thrusts, opposing school closures, and claiming Labour leader Johann Lamont's "cuts commission" threatens the "people's priorities".

The main issue on the doorsteps has been the plan by Fife Council to close three schools, particularly the popular and successful Pitcorthie Primary, which is 96% full and has been held up as an example of educational excellence. "It's a ludicrous proposal which the Labour candidate was happy to vote through and is now blaming officials for. It goes to the heart of candidate trust," she said.

On the Bill Walker factor, Ms Somerville said people wanted to know about how the SNP had now tightened up procedures, and claimed that given Labour's many problems in Falkirk they were in no position to claim the moral high ground.

The Labour candidate, Cara Hilton, is steeped in her party which she joined at 15, but she only became a councillor last year and as a relatively inexperienced candidate has been heavily protected by minders.

It takes a couple of attempts to get her to engage on the issue of planned school closures in her own back yard, but she insists that although she voted in favour of the review process she had been "working with the local parents since before my SNP opponent even heard of Pitcorthie Primary".

Although all eyes will be on the Labour-SNP battle, there are other intriguing aspects, not least whether university lecturer Susan Leslie can arrest the slide in Liberal Democrat fortunes. It was the slump in LibDem support which allowed the SNP to come through the middle from third place to beat Labour two years ago.

Another intriguing factor is the intervention of Ukip. Scottish organiser Peter Adam has lived in Fife for 20 years and is treasurer of Kirkcaldy West Community Council. There was controversy over his eligibility to stand given his membership of Fife Health Board, from which he has since resigned.

Conservative James Reekie stood in 2011 and got just 7.1% of the vote. If Ukip can take even a small amount of that share it could lead to a lost deposit for the Tories. There is also a Green candidate, plus an independent who has previously stood as a Scottish Jacobite.

Even small numbers of votes which might have gone to the SNP could aid Labour's cause.