For fruit flies one usually wants pure lineages for specific alleles, corresponding to distinct phenotypes. One cannot arrive to such a state by merely enclosing the flies for many generations - in this case one will quickly end up in the situation of Hardy-Weinberg equilibrium, where all the alleles are present in constant proportions, not changing with time. Of course, in a finite population one expects that eventually one allele fixes itself, but that may take a rather long time in absence of selection. Thus, in practice one separates the desired phenotypes in every generation, and and makes them breed among themselves. In fact, this is pretty much what Mendel did with peas to obtain pure lineages - it is worth reviewing this chapter.
Now, it is always risk that the population is not 100% pure, just as there is always a possibility that other genes contribute to the trait of interest. Here is where the (bio)statistical analysis comes in: testing for significance of the effect and filtering out random effects.
Update
Just to provide a quick calculation: suppose that we have alleles A and a, with A being the dominant one. In every generation we remove the undesired genotype aa. Initially we have the genotype frequencies of AA,Aa,aa given by $P, H, Q=0$,
where $P+H=1$. The allele frequencies are $$p=P+\frac{H}{2},q=\frac{H}{2}$$
After crossing we obtain the allele frequencies $p^2, 2pq,q^2$, which after removing the aa genotype give:
$$
P'=\frac{p^2}{p^2+2pq}=\frac{p}{p+2q}, H'=\frac{2pq}{p^2+2pq}=\frac{2q}{p+2q}
$$
The new allele frequencies are
$$p'=\frac{p+q}{p+2q}=\frac{1}{1+q}, q'=\frac{q}{p+2}=\frac{q}{1+Q},$$
where I used the fact that $p+q=1$.
More generally, the frequency of the unwanted allele in generation $t+1$, in terms of the frequencies in the previous generation, is given by
$$
q_{t+1}=\frac{q_t}{1+q_t}
$$
The solution to this difference equation is
$$
q_t=\frac{q_0}{1+tq_0}.
$$
Now, if we want the frequency of the unwanted allele to be below teh desired threshold $\alpha$, we must solve inequality $q_t<\alpha$, obtaining
$$
t>\frac{q_0}{\alpha}-1
$$
generations. A good choice of $\alpha$ is $1/N$, where $N$ is the number of individuals in the population (than after $Nq_0-1$ generations we are likely to have no more than one individual carrying the minority allele).
Remark
A similar calculation can be found in connection with strong selection, under conditions of complete dominance: if $s=1$, the aa genotype is completely eliminated at each generation. See, e.g., Introduction to Quantitative Genetics by Douglas Falconer.