Yes, but you need to be a bit careful. Formally you are just embedding the space of integrable functions $\mathbb{R} \to \mathbb{R}$ into the space of integrable functions $\mathbb{R} \to \mathbb{C}$ (which is its complexification), and this embedding is compatible with taking antiderivatives. Even though complex numbers appear in the calculation, because the original function you're integrating is real, the final answer must necessarily be real, so the imaginary parts have to cancel out somehow. Note that it is not necessary to allow $x$ to be complex.
The simplest examples where everything works out quite cleanly involve trigonometric functions. For example you can see this old thread which explains how to compute $\int_0^{2 \pi} \sin^{100} x \, dx$ by writing $\sin x = \frac{e^{ix} - e^{-ix}}{2i}$ and then expanding using the binomial theorem.
The case of rational functions is more complicated because logarithms appear. $\int \frac{1}{x^2 + 1} \, dx$ is a good example so let's work through that in some detail. The partial fraction decomposition is
$$\frac{1}{(x + i)(x - i)} = \frac{1}{2i} \left( \frac{1}{x + i} - \frac{1}{x - i} \right)$$
and integrating formally gives an antiderivative of
$$\int \frac{1}{1 + x^2} \, dx = \frac{1}{2i} \left( \ln (x + i) - \ln (x - i) \right).$$
But is this the right answer? We were expecting $\arctan x$, of course. This answer is actually correct if properly interpreted, but there is a subtlety here. Even if $x$ is real, $x + i$ and $x - i$ are complex, so to make sense of these expressions we have to pick a branch of the complex logarithm, which complicates things; different choices will differ by a constant (which isn't a big deal, that's just how antiderivatives work), but we also have to pick a branch cut, which is a complication you might want to avoid since the final answer shouldn't really depend on this choice.
To make things less confusing I would personally rewrite the partial fraction decomposition slightly, as
$$\frac{1}{(1 + ix)(1 - ix)} = \frac{1}{2} \left( \frac{1}{1 + ix} + \frac{1}{1 - ix} \right)$$
which, again integrating formally, gives an antiderivative of
$$\int \frac{1}{1 + x^2} \, dx = \frac{1}{2} \left( \frac{\log (1 + ix)}{i} - \frac{\log (1 - ix)}{i} \right)$$
where we define
$$\log (1 + z) = \sum_{n \ge 1} (-1)^{n-1} \frac{z^n}{n}$$
even if $z$ is complex (as long as $|z| < 1$). Now there's no issue with branches and branch cuts, or rather, the choice to use the Taylor series around $1$ makes this choice for us. From here we can write
$$\log (1 + ix) - \log (1 - ix) = \log \frac{1 + ix}{1 - ix}$$
(this is no longer entirely obvious with our specific choice of branch of the logarithm and needs to be checked) and now we need to stop and think a bit about what this function is actually doing. If $x$ is real, $1 + ix$ is a complex number which has polar form $re^{i \theta}$ such that $x = \tan \theta$. Then $1 - ix$ is its complex conjugate, which is $re^{-i \theta}$. So their ratio is $e^{2 i \theta}$. This gives, again at least formally,
$$\frac{1}{2i} \left( \log (1 + ix) - \log (1 - ix) \right) = \frac{1}{2i} \log e^{2i \theta} = \theta = \arctan x.$$
But you might rightfully feel a little wary of this argument, since it involves applying logarithm rules to the complex logarithm (again, even if $x$ is real) which generally only hold up to a multiple of $2 \pi i$, due to the whole issue with branches, and we also need to potentially say some things about the domain and range of $\arctan$ and so forth. You can check that everything is fine (computationally the worst that'll happen is that you pick up an additive constant, which is not an issue for antiderivatives) but at this point it is maybe more work than it's worth.
Best Answer
Let us try to understand the situation by using example.
If we add up $\frac{1}{x-1}$, $\frac{1}{(x-1)^2}$ and $\frac{1}{x+1}$, we will get $\frac{2x^2-2x+1}{(x-1)^2(x+1)}$.
That is
$$\frac{1}{x-1}+\frac{1}{(x-1)^2}+\frac{1}{x+1}=\frac{2x^2-2x+1}{(x-1)^2(x+1)}.$$
The task of partial fraction is to start from $$\frac{2x^2-2x+1}{(x-1)^2(x+1)}$$ and try to get back
$$\frac{1}{x-1}+\frac{1}{(x-1)^2}+\frac{1}{x+1}$$
Obviously we can never come to $\frac{1}{x-1}+\frac{1}{(x-1)^2}+\frac{1}{x+1}$ by assuming that the answer is of the form $\frac{A}{(x-1)^2}+\frac{B}{x+1}.$
The whole idea is to let $$\frac{2x^2-2x+1}{(x-1)^2(x+1)}=\frac{P(x)}{(x-1)^2}+\frac{Q(x)}{x+1}$$ where $\deg P(x) \lt \deg (x-1)^2$ and $\deg Q(x) \lt \deg (x+1).$
Thus $P(x)=Ax+B$ and $Q(x)=C$ for some constants $A, B$ and $C$.
Hence we have $$\frac{2x^2-2x+1}{(x-1)^2(x+1)}=\frac{Ax+B}{(x-1)^2}+\frac{C}{x+1}.$$
Since $Ax+B=A(x-1)+(A+B)$, we have $$\frac{2x^2-2x+1}{(x-1)^2(x+1)}=\frac{A(x-1)+A+B}{(x-1)^2}+\frac{C}{x+1}$$ i.e. $$\frac{2x^2-2x+1}{(x-1)^2(x+1)}=\frac{A}{x-1}+\frac{B'}{(x-1)^2}+\frac{C}{x+1}$$ where $B'=A+B.$