Let $k$ be a locally integrable function representing $\partial_1 f$, so
$$\int k(x,y)\varphi(x,y)\,dx\,dy = -\int f(x,y)\partial_1\varphi(x,y)\,dx\,dy = - \int g(x)\left(\int \partial_1\varphi(x,y)\,dy\right)\,dx$$
for all test functions $\varphi$.
Since $f$ does not depend on $y$, we have $\partial_2 f = 0$, and therefore also $\partial_2 \partial_1 f = 0$. That means
$$\int k(x,y)\partial_2 \varphi(x,y)\,dx\,dy = 0$$
for all $\varphi \in \mathscr{D}(\mathbb{R}^2)$. Choose $\eta \in \mathscr{D}(\mathbb{R})$ with
$$\int_\mathbb{R} \eta(t)\,dt = 1.$$
Then, for every $\varphi\in \mathscr{D}(\mathbb{R}^2)$, the function
$$S(\varphi) \colon (x,y) \mapsto \varphi(x,y) - \eta(y)\cdot \int_\mathbb{R} \varphi(x,u)\,du$$
satisfies
$$\int_{\mathbb{R}} S(\varphi)(x,y)\,dy = 0$$
for all $x\in\mathbb{R}$, therefore $S(\varphi) = \partial_2 \psi$ for some $\psi \in \mathscr{D}(\mathbb{R}^2)$, whence
$$\begin{align}
\int_{\mathbb{R}^2} k(x,y) \varphi(x,y)\,dy\,dx &= \int_{\mathbb{R}^2} k(x,y) \eta(y)\left(\int_\mathbb{R} \varphi(x,u)\,du\right)\,dy\,dx\\
&= \int_\mathbb{R} \left(\int_\mathbb{R} k(x,y)\eta(y)\,dy\right) \left(\int_\mathbb{R} \varphi(x,u)\,du\right)\,dx\\
&= \int_{\mathbb{R}^2} \left(\int_\mathbb{R} k(x,y)\eta(y)\,dy\right)\varphi(x,u)\,du\,dx\\
&= \int_{\mathbb{R}^2} h(x)\varphi(x,u)\,du\,dx,
\end{align}$$
where
$$h(x) = \int_\mathbb{R} k(x,y)\eta(y)\,dy$$
is a locally integrable function depending only on $x$.