The following worked for me. Note the absence of the parameters passed to test. The python file is as stated in the question.
subroutine test()
use iso_fortran_env, only stdout => output_unit
!f2py intent(callback) py_func
external py_func
integer py_func
integer y,x
!f2py y = py_func(x)
integer :: a
integer :: b
a = 12
write(stdout, *) a
end subroutine
As an aside, I then wrapped py_func
in a subroutine so that I could call it without having to declare the following in every file / function I use it:
integer y
y = py_func(x)