Talk:Web Development with Webmachine for Erlang

Latest comment: 10 years ago by Thyrsus in topic mnesia unit tests

I'm trying to follow along. After creating api_tests.py, when I run command "python -m unittest api_tests.py -v" I get

 $ python -m unittest api_tests.py -v
 Traceback (most recent call last):
   File "/usr/lib64/python2.7/runpy.py", line 162, in _run_module_as_main
     "__main__", fname, loader, pkg_name)
   File "/usr/lib64/python2.7/runpy.py", line 72, in _run_code
     exec code in run_globals
   File "/usr/lib64/python2.7/unittest/__main__.py", line 12, in <module>
     main(module=None)
   File "/usr/lib64/python2.7/unittest/main.py", line 94, in __init__
     self.parseArgs(argv)
   File "/usr/lib64/python2.7/unittest/main.py", line 149, in parseArgs
     self.createTests()
   File "/usr/lib64/python2.7/unittest/main.py", line 158, in createTests
     self.module)
   File "/usr/lib64/python2.7/unittest/loader.py", line 128, in loadTestsFromNames
     suites = [self.loadTestsFromName(name, module) for name in names]
   File "/usr/lib64/python2.7/unittest/loader.py", line 100, in loadTestsFromName
     parent, obj = obj, getattr(obj, part)
 AttributeError: 'module' object has no attribute 'py'

Fedora 17, python-2.7.3-7.2.fc17.x86_64,python-libs-2.7.3-7.2.fc17.x86_64 (which includes unittest)

The solution appears to use instead

 python -m unittest api_tests

Also, as of a few minutes ago, the default port is 8000, not 8888, so I changed that in api_tests.py.

Thyrsus (discusscontribs) 07:03, 5 June 2013 (UTC)Reply

mnesia unit tests edit

In my copious spare time, I'll propose some Fixtures to add to the test/prp_schema_tests.erl file, but for now I'll note that to run the tests I needed to do the following:

  • change the start.sh script to include "-s mnesia start" among its arguments like so:
   #!/bin/sh
   cd `dirname $0`
   exec erl -pa $PWD/ebin $PWD/deps/*/ebin -boot start_sasl -s mnesia start -s reloader -s prp
  • after invoking "./start.sh", at the resulting erlang prompt invoke
   prp_schema:init_tables().
   prp_schema:fill_with_dummies().
   c("test/prp_schema_tests").

I'll also note that, even though "-s reload" was supposed to note changed binaries and reload them with their new functionality, it didn't work for me; to get any changes recognized, I had to "q()." out of the erlang shell, run "./rebar compile" and then "./start.sh" again.

   Thyrsus (discusscontribs) 02:58, 10 July 2013 (UTC)Reply

Turn on tracing for debugging edit

The tracing described requires that one create a directory "traces" as a sibling to ebin, Makefile, etc., otherwise the web server returns a 500 error and this message in the shell:

   =ERROR REPORT==== 9-Jul-2013::23:11:38 ===
   webmachine error: path="/paper/1"
   {error,{badmatch,{error,enoent}}}
   1> 
   =ERROR REPORT==== 9-Jul-2013::23:11:38 ===
   Error in process <0.117.0> with exit value: {undef,[{webmachine_logger,log_access,[{wm_log_data,undefined,{1373,425898,927101},'GET',{5,{"user-agent",{'User-Agent',"python-requests/1.1.0 CPython/2.7.3 Linux/3.9.8-100.fc17.x86_64"},{"accept",{'Accept',"*/*"},nil,{"accept-encodin... 

It would be helpful if a reference to documentation of the tracing facility were included. As it was, I found the problem by running the web server process tree under "strace -f -o wm -s 255 ./start.sh" and, given the "enoent" hint, looking for ENOENT returns from system calls (of which there were plenty, the vast majority ensuing from path searches).

Return to "Web Development with Webmachine for Erlang" page.