allure-framework / allure-pytest

Deprecated, please use https://github.com/allure-framework/allure-python instead
Other
171 stars 83 forks source link

Is it possible to rename test cases names? #47

Closed alvassin closed 9 years ago

alvassin commented 10 years ago

I set item name in conftest.py:

def pytest_runtest_setup(item):
    item.name = '%custom_name%'
    print item.name # changed

but in xml it stays with old names:

test_name[data0]
test_name[data1]

Can i somehow rename testcase name?

mavlyutov commented 10 years ago

it is not recommended to rename testcases directly in pytest, cause it may lead to unknown consequences. but you could rename testcases in allure report. smh like this:

@pytest.fixture(autouse=True, scope="module")
def renamer(request):
    config = request.config
    my_super_suffix = 'ololo'
    if hasattr(config, '_allurelistener'):
        config._allurelistener.impl.testsuite.name += '[%s]' % my_super_suffix
baev commented 10 years ago

@mavlyutov why you can't just change title?

mavlyutov commented 10 years ago

@baev just imagine a situation, when you have one test and you want to run it on different platforms. x86 and x64 for example

baev commented 10 years ago

what's the problem with different platforms?

mavlyutov commented 10 years ago

you'll have report with main page containing these testsuites: my_super_test my_super_test

in my case, you could achieve that one: my_super_test[x32] my_super_test[x64]

baev commented 10 years ago

ok, I got it. This other situation. But I still don't understand why you can't change title. An example, in JUnit we can use @Title annotation:

@Title("Hi, I'm custom test name")
@Test
public void myTestWithCustimTitle() {
    //some staff
}

and in report you got Hi, I'm custom test name.

mavlyutov commented 10 years ago
  1. you need to wrap every single tests with custom title. moreover, at some cases you need to have some logic in titles. e.g. platforms. our testcases can automatically detect platforms and add a special suffix to testnames.
  2. unfortunately, allure-python adaptor knows nothing about titles =(
baev commented 10 years ago

We have parameters logic - https://github.com/allure-framework/allure-core/wiki/Parameters. U can use it to mark test with some data, such as platform etc

Btw, maybe we remove titles from model, https://github.com/allure-framework/allure-core/issues/408.

mavlyutov commented 10 years ago

hmm, I'm going to look at it, thank you!

alvassin commented 10 years ago

@mavlyutov Thank you very much! Very useful!

pupssman commented 10 years ago

@baev how do we specify those parameters via XML?

alvassin commented 10 years ago

Btw... finally i got another result:

ololo[data0]
ololo[data1]

@mavlyutov is it possible to change parameter string in the allure report? data0 or data1 to my custom?

mavlyutov commented 10 years ago

hmm.. looks like you want to discover parameter ids. see http://pytest.org/latest/parametrize.html#_pytest.python.Metafunc.parametrize ids – list of string ids each corresponding to the argvalues so that they are part of the test id. If no ids are provided they will be generated automatically from the argvalues.