# Help: example PTL test

**URL:** <https://community.openpbs.org/t/help-example-ptl-test/2783>\
**Category:** Users/Site Administrators\
**Created:** [September 8, 2021, 7:28pm UTC](https://community.openpbs.org/t/help-example-ptl-test/2783 "2021-09-08T19:28:17Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![dtalcott](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.openpbs.org/dtalcott/32/410_2.png) [@dtalcott](https://community.openpbs.org/u/dtalcott)\
**Post date:** [September 8, 2021, 7:28pm UTC](https://community.openpbs.org/t/help-example-ptl-test/2783/1 "2021-09-08T19:28:17Z")

</div>

I’m working on a bug report, but would also like to create a PTL test that shows the bug. However, I don’t want to install the test in /opt/ptl/tests until I have debugged it. I’ve read through the docs under [https://openpbs.atlassian.net/wiki/spaces/DG/pages/518029315/Testing+Your+Code](https://openpbs.atlassian.net/wiki/spaces/DG/pages/518029315/Testing+Your+Code) and [https://openpbs.atlassian.net/wiki/spaces/PD/pages/1319829507/Enhancement+of+pbs+benchpress+to+run+test+case+from+non-test+directory](https://openpbs.atlassian.net/wiki/spaces/PD/pages/1319829507/Enhancement+of+pbs+benchpress+to+run+test+case+from+non-test+directory), but am not having much luck.

Could someone show me the steps to use pbs\_benchpress to run a new test (assuming I have PTL running fine for the existing tests)?

For a concrete example, make a local copy of the test at /opt/ptl/tests/functional/pbs\_dup\_acc\_log\_for\_resv.py, change it to have a reserve\_end 61 seconds in the future, and test the result. (This is not the bug, just a simple test.)

This is what I get:

```auto
$ pwd
/home/dtalcott/work/ptl_tests
$ pbs_benchpress -f ./pbs_dup_acc_log_for_resv.py -L -l DEBUG
2021-09-08 11:50:56,177 DEBUG included_tests:{' __only__ ts__': ['PBSTestSuite'], '__only __tc__': []}
2021-09-08 11:50:56,178 DEBUG included_tests(copy):{' __only__ ts__': ['PBSTestSuite'], '__only __tc__': []}
2021-09-08 11:50:56,178 DEBUG excluded_tests:{' __only__ ts__': [], '__only __tc__': []}
2021-09-08 11:50:56,184 DEBUG check_unknown called
2021-09-08 11:50:56,184 ERROR unknown testsuite(s): PBSTestSuite

```

Nothing I have tried gets past the “unknown testsuite(s)” error. I can use -t _xyz_ to change the suite it complains about, but that’s it. I haven’t found a value for _xyz_ that it likes.

Thanks.

---

<div class="post-metadata">

**Author:** ![agurban](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.openpbs.org/agurban/32/67_2.png) [@agurban](https://community.openpbs.org/u/agurban)\
**Post date:** [September 8, 2021, 9:35pm UTC](https://community.openpbs.org/t/help-example-ptl-test/2783/2 "2021-09-08T21:35:25Z")

</div>

Looks as if the Confluence pages need an update. When you get that info, can you give it to me? Thanks.

---

<div class="post-metadata">

**Author:** ![agrawalravi90](https://avatars.discourse-cdn.com/v4/letter/a/848f3c/32.png) [@agrawalravi90](https://community.openpbs.org/u/agrawalravi90)\
**Post date:** [September 8, 2021, 10:03pm UTC](https://community.openpbs.org/t/help-example-ptl-test/2783/3 "2021-09-08T22:03:20Z")

</div>

If you are able to run existing tests in the same directory, then I think there might be a Python bug in your new test file. On the other hand, if your new test file lives in a different directory than the existing tests, then try pointing PYTHONPATH to where you installed the ptl module. e.g - PYTHONPATH=/opt/ptl/lib/python3.6/site-packages pbs\_benchpress -f pbs\_dup\_acc\_log\_for\_resv.py -L -l DEBUG

---

<div class="post-metadata">

**Author:** ![dtalcott](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.openpbs.org/dtalcott/32/410_2.png) [@dtalcott](https://community.openpbs.org/u/dtalcott)\
**Post date:** [September 8, 2021, 11:13pm UTC](https://community.openpbs.org/t/help-example-ptl-test/2783/4 "2021-09-08T23:13:02Z")

</div>

I don’t think that’s it:

```auto
> ls -l
total 8
-rw-r--r-- 1 501 games 2405 Sep 8 15:22 pbs_dup_acc_log_for_resv.py
-rw-r--r-- 1 501 games 2519 Sep 8 10:50 pbs_grunt.py
> echo $PYTHONPATH
:/opt/ptl/lib/python3.6/site-packages:/opt/pbs/lib/python/altair
> pbs_benchpress -f ./pbs_dup_acc_log_for_resv.py -L
2021-09-08 15:18:49,141 ERROR unknown testsuite(s): PBSTestSuite

```

And, I don’t think there is a problem with the test itself. The file pbs\_dup\_acc\_log\_for\_resv.py is a straight copy of /opt/ptl/tests/functional/pbs\_dup\_acc\_log\_for\_resv.py.

A clue: If I introduce a python error in my file, but tell pbs\_benchpress to run one of the standard tests (-t TestDupAccLogForResv.test\_accounting\_logs), then it runs the standard test, then issues a python error msg.

```auto
> pbs_benchpress -t TestDupAccLogForResv.test_accounting_logs
2021-09-08 16:03:20,930 INFO input command: pbs_benchpress -t TestDupAccLogForResv.test_accounting_logs
2021-09-08 16:03:20,931 INFO param: None
2021-09-08 16:03:20,931 INFO ptl version: 20.0.1_lessNAS
2021-09-08 16:03:20,934 INFO platform: Linux server2.local 3.10.0-1160.el7.x86_64 #1 SMP Mon Oct 19 16:18:59 UTC 2020 x86_64 x86_64
2021-09-08 16:03:20,934 INFO python version: 3.6.8
2021-09-08 16:03:20,934 INFO user: dtalcott
2021-09-08 16:03:20,934 INFO --------------------------------------------------------------------------------
2021-09-08 16:03:20,934 INFO Cleaning up temporary files

2021-09-08 16:03:21,343 INFO Cleaning up /tmp dir
2021-09-08 16:03:21,343 INFO Cleaning up /var/tmp dir
2021-09-08 16:03:22,693 INFO ======================================================================
2021-09-08 16:03:22,694 INFO suite name: Failure
2021-09-08 16:03:22,694 INFO suite docstring: 
Unloadable or unexecutable test.

    A Failure case is placed in a test suite to indicate the presence of a
    test that could not be loaded or executed. A common example is a test
    module that fails to import.
    
[...]
2021-09-08 16:01:48,194 INFO =======================================
2021-09-08 16:01:48,194 INFO Completed TestDupAccLogForResv tearDown
2021-09-08 16:01:48,195 INFO =======================================
2021-09-08 16:01:48,199 INFO ok

2021-09-08 16:01:48,202 INFO     
2021-09-08 16:01:48,202 INFO ======================================================================
2021-09-08 16:01:48,202 INFO ERROR: Failure: SyntaxError (invalid syntax (pbs_grunt.py, line 58))

2021-09-08 16:01:48,202 INFO ___m_oo_m___

```

So, pbs\_benchpress sees my test, but I don’t know how to get it to run it. I **think** my problem is that I cannot come up the right value for the **-t** option to pbs\_benchpress.

---

<div class="post-metadata">

**Author:** ![agrawalravi90](https://avatars.discourse-cdn.com/v4/letter/a/848f3c/32.png) [@agrawalravi90](https://community.openpbs.org/u/agrawalravi90)\
**Post date:** [September 9, 2021, 5:11am UTC](https://community.openpbs.org/t/help-example-ptl-test/2783/5 "2021-09-09T05:11:49Z")

</div>

hmm ok … I think the problem might be that you are running the test out of a directory that doesn’t have the functional/\_\_init\_\_.py, which is where we define TestFunctional, which inherits from PBSTestSuite. All the tests inside functional/ inherit TestFunctional, including TestDupAccLogForResv. What I usually do is that I copy over the pbs source tree, then go inside openpbs/test/tests/functional/ and create my new test file there. If that doesn’t work for you, then you can try adding “from ptl.utils.pbs\_testsuite import \*” to your test file, that should help it find PBSTestSuite.

---

<div class="post-metadata">

**Author:** ![dtalcott](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.openpbs.org/dtalcott/32/410_2.png) [@dtalcott](https://community.openpbs.org/u/dtalcott)\
**Post date:** [September 9, 2021, 7:59pm UTC](https://community.openpbs.org/t/help-example-ptl-test/2783/6 "2021-09-09T19:59:47Z")

</div>

I finally got it to work. Here is my dummy test, called “pbs\_hello.py”

```auto
# coding: utf-8

from tests.functional import *

class TestExample(TestFunctional):

    """
    This test suite is just an example
    """

    def test_hello(self):
        """
        Produce a hello world message
        """
        our_queue = 'workq'
        our_text = 'Hello world'
        a = {'comment': our_text}
        self.server.manager(MGR_CMD_SET, QUEUE, a, id=our_queue)
        self.server.expect(QUEUE, a, id=our_queue)

```

Here are the steps to run it, assuming you can already run pbs\_benchpress with the installed tests.

```auto
mkdir my_ptl_tests
cd my_ptl_tests/
vi pbs_hello.py

mkdir tests tests/functional
ln -s /opt/ptl/tests/functional/ __init__.py tests/functional/
ln -s ../../pbs_hello.py tests/functional/ # See note
touch __init__.py

pbs_benchpress -t TestExample.test_hello

```

**Note** : This symlink makes your test appear to be in the tests/functional hierarchy. You could put it there directly, but I prefer to work with it at the my\_ptl\_tests level.

It would be nice if someone could verify that it works for them also.

FWIW, My original test case now works and crashes the server, as expected. 🙂
