Need help packaging python-thewalrus

Hello,

I have been trying to package python-thewalrus.
https://build.opensuse.org/package/show/home:andythe_great/python-thewalrus
https://github.com/XanaduAI/thewalrus/issues/184

But the error is always this.

   58s] ==================================== ERRORS ====================================
   58s] ___________ ERROR collecting thewalrus/tests/test_fock_gradients.py ____________
   58s] ImportError while importing test module '/home/abuild/rpmbuild/BUILD/thewalrus-0.12.0/thewalrus/tests/test_fock_gradients.py'.
   58s] Hint: make sure your test modules/packages have valid Python names.
   58s] Traceback:
   58s] thewalrus/tests/test_fock_gradients.py:16: in <module>
   58s]     from thewalrus.fock_gradients import (
   58s] E   ModuleNotFoundError: No module named 'thewalrus'


So I tired building it locally with pip and test with pytest.
I download the thewalrus-0.12.0.tar.gz from github and install with

pip install thewalrus-0.12.0.tar.gz
cd /home/andy/.local/lib/python3.8/site-packages/thewalrus
pytest
=========================================================================================================== test session starts ============================================================================================================
platform linux -- Python 3.8.4, pytest-5.4.3, py-1.9.0, pluggy-0.13.1
benchmark: 3.2.3 (defaults: timer=time.perf_counter disable_gc=False min_rounds=5 min_time=0.000005 max_time=1.0 calibration_precision=10 warmup=False warmup_iterations=100000)
rootdir: /home/andy/.local/lib/python3.8/site-packages/thewalrus/tests
plugins: asdf-2.6.0, asyncio-0.14.0, aspectlib-1.5.0, benchmark-3.2.3
collected 951 items                                                                                                                                                                                                                        

test_fock_gradients.py ...............                                                                                                                                                                                                 1%]
test_hafnian.py ...........................................................................................                                                                                                                           11%]
test_hafnian_approx.py .......                                                                                                                                                                                                        11%]
test_hafnian_repeated.py ........................................                                                                                                                                                                     16%]
test_hermite_multidimensional.py ........                                                                                                                                                                                             16%]
test_integration.py .......                                                                                                                                                                                                           17%]
test_permanent.py ........................                                                                                                                                                                                            20%]
test_quantum.py ....................................................................................................................................................................................................................  42%]
....................................................................................................................................................................................................................................  66%]
.....................................................................................................                                                                                                                                 77%]
test_reference.py ...........................                                                                                                                                                                                         79%]
test_samples.py ........................................                                                                                                                                                                              84%]
test_samples_classical.py .......                                                                                                                                                                                                     84%]
test_symplectic.py .....................................................................................                                                                                                                              93%]
test_torontonian.py ...........................................................                                                                                                                                                      [100%]

===================================================================================================== 951 passed in 436.84s (0:07:16) ======================================================================================================

Which passed flawlessly.

I’m not sure what the error implies.
This also happen to pythno-sat-stac
https://build.opensuse.org/package/show/home:andythe_great/python-sat-stac

Thanks.

Hi
Not sure it’s really a python- package since it’s a python library, not a module, your probably better off to just package as thewalrus.

AFAIKT, you need to cd into the test directory, then call your macro.

I have tried,


cd thewalrus/tests
%pytest
cd ../../ 

cd thewalrus
%pytest
cd .. 

but still same error. It seems that pytest could not find the test for some reason, or I might understand it wrong.

  296s] ============================= test session starts ==============================
  296s] platform linux -- Python 3.8.4, pytest-5.4.3, py-1.9.0, pluggy-0.13.1 -- /usr/bin/python3
  296s] cachedir: .pytest_cache
  296s] benchmark: 3.2.3 (defaults: timer=time.perf_counter disable_gc=False min_rounds=5 min_time=0.000005 max_time=1.0 calibration_precision=10 warmup=False warmup_iterations=100000)
  296s] rootdir: /home/abuild/rpmbuild/BUILD/thewalrus-0.12.0
  296s] plugins: benchmark-3.2.3
  298s] collecting ... collected 0 items / 13 errors
  298s] 
  298s] ==================================== ERRORS ====================================
  298s] ___________ ERROR collecting thewalrus/tests/test_fock_gradients.py ____________
  298s] ImportError while importing test module '/home/abuild/rpmbuild/BUILD/thewalrus-0.12.0/thewalrus/tests/test_fock_gradients.py'.
  298s] Hint: make sure your test modules/packages have valid Python names.
  298s] Traceback:
  298s] test_fock_gradients.py:16: in <module>
  298s]     from thewalrus.fock_gradients import (
  298s] E   ModuleNotFoundError: No module named 'thewalrus'

I will change the package name, thanks.

In the case of sat-stac, it solve the issue for me by cd into the test, but it does not work for thewalrus.

Hi
If you rename and give me a link, will branch and have a play :wink:

Here

https://build.opensuse.org/package/show/home:andythe_great/thewalrus

Thanks for the help.

Hi
The tests are to be run after install as per the source instructions, nothing to do at build time :wink:

Is it normal to do it like this? Isn’t the package suppose to test as it is installed?

Hi
You could add as post install option, in this case as the packager/tester I would suggest you run locally after install…

I tried using gtest instead of pytest as the doc suggest. The check is now passing.
But is it ok to do it this way?

%check
cd tests
%make_build test
cd .. 

Hi
If it works, don’t see why not :wink:

Thanks for the help

Update:
using

%check
%pytest_arch

works

Hi
Ahh good to know :slight_smile: