Solution (source code)

= Solution

Put $S=\sum_i(x_i-\bar x)^2$ and $q=S/\sigma_0^2$. Under the <null hypothesis>, maximizing over the nuisance <mean> gives $\widehat\mu_0=\bar x$. The unrestricted <normal mean and variance maximum-likelihood estimators> are $\widehat\mu=\bar x$, $\widehat{\sigma^2}=S/n$. Thus, for $S>0$,
$$
\lambda(\boldsymbol x)=\frac{(2\pi\sigma_0^2)^{-n/2}e^{-S/(2\sigma_0^2)}}{(2\pi S/n)^{-n/2}e^{-n/2}}
=\boxed{\left(\frac qn\right)^{n/2}e^{(n-q)/2}}.
$$
The <likelihood-ratio test statistic> is consequently
$$
\boxed{W=-2\log\lambda=q-n-n\log(q/n)}.
$$
The usual model assumes $n\geq2$. The event $S=0$ has <probability> zero under a nondegenerate <normal distribution>; at that observation the unrestricted likelihood is unbounded as the variance tends to zero, and the ratio has limiting value zero. This is the <likelihood-ratio test for a normal variance> with unknown mean.