How do I run a single test with Nose in Pylons

后端 未结 6 1324
星月不相逢
星月不相逢 2021-01-29 23:09

I have a Pylons 1.0 app with a bunch of tests in the test/functional directory. I\'m getting weird test results and I want to just run a single test. The nose documentation say

相关标签:
6条回答
  • 2021-01-29 23:36

    I have to add the ".py" file extension, that is,

    r'/path_to/my_file.py:' +  r'test_func_xy'
    

    Maybe this is because I don't have any classes in the file. Without the .py, nose was complaining:

    Can't find callable test_func_xy in file /path_to/my_file: file is not a python module

    And this although I have an __init__.py in the folder /path_to/.

    0 讨论(0)
  • 2021-01-29 23:41

    The following worked for me just well:

    nosetests test_file.py:method_name
    

    Note that my tests where not in a class. Test methods were in a single file.

    0 讨论(0)
  • 2021-01-29 23:43

    nosetests appname.tests.functional.test_controller should work, where the file is named test_controller.py.

    To run a specific test class and method use a path of the form module.path:ClassNameInFile.method_name, that is, with a colon separating the module/file path and the objects within the file. module.path is the relative path to the file (e.g. tests/my_tests.py:ClassNameInFile.method_name).

    0 讨论(0)
  • 2021-01-29 23:51

    For me using Nosetests 1.3.0 these variants are working (but make sure you have __init__.py in your tests folder):

    nosetests [options] tests.ui_tests
    nosetests [options] tests/ui_tests.py
    nosetests [options] tests.ui_tests:TestUI.test_admin_page
    

    Note that single colon between module name and class name.

    0 讨论(0)
  • 2021-01-29 23:51

    For nosetests 1.3.7, you need to do:

    nosetests --tests=tests.test_something.py,tests.test_something_else.py.

    0 讨论(0)
  • 2021-01-30 00:02

    I wrote this small script, based on the previous answers:

    #!/usr/bin/env bash
    
    # 
    # Usage:
    # 
    #     ./noseTest <filename> <method_name>
    # 
    # e.g.:
    # 
    #     ./noseTest test/MainTest.py mergeAll
    #     
    # It is assumed that the file and the test class have the _same name_ 
    # (e.g. the test class `MainTest` is defined in the file `MainTest.py`).
    # If you don't follow this convention, this script won't work for you.
    #
    
    testFile="$1"
    testMethod="$2"
    
    testClass="$(basename "$testFile" .py)"
    
    nosetests "$testFile:$testClass.test_$testMethod"
    
    0 讨论(0)
提交回复
热议问题