How to use test_reporting_session method in Lemoncheesecake

Best Python code snippet using lemoncheesecake

test_report_slack.py

Source:test_report_slack.py Github

copy

Full Screen

...5from helpers.cli import cmdout6import lemoncheesecake.api as lcc7from lemoncheesecake.reporting.backends.slack import SlackReportingBackend8from lemoncheesecake.exceptions import UserError9def _test_reporting_session(**vars):10 backend = SlackReportingBackend()11 with env_vars(**vars):12 return backend.create_reporting_session(None, None, None, None)13@pytest.fixture14def slacker_mock(mocker):15 mocker.patch("slacker.Slacker")16 return mocker17@lcc.suite("suite")18class suite_sample:19 @lcc.test("test")20 def test(self):21 lcc.log_info("do stuff")22try:23 import slacker24except ImportError:25 pass # slacker is not installed (slack is an optional feature), skip tests26else:27 def test_create_reporting_session_success(tmpdir):28 _test_reporting_session(LCC_SLACK_AUTH_TOKEN="sometoken", LCC_SLACK_CHANNEL="#chan")29 def test_create_reporting_session_missing_config(tmpdir):30 with pytest.raises(UserError, match="missing environment variable"):31 _test_reporting_session(LCC_SLACK_AUTH_TOKEN=None, LCC_SLACK_CHANNEL=None)32 def test_create_reporting_session_message_variable_ok(tmpdir):33 _test_reporting_session(34 LCC_SLACK_AUTH_TOKEN="sometoken", LCC_SLACK_CHANNEL="#chan",35 LCC_SLACK_MESSAGE_TEMPLATE="result: {passed_pct}"36 )37 def test_create_reporting_session_bad_message_variable(tmpdir):38 with pytest.raises(UserError, match="unknown variable"):39 _test_reporting_session(40 LCC_SLACK_AUTH_TOKEN="sometoken", LCC_SLACK_CHANNEL="#chan",41 LCC_SLACK_MESSAGE_TEMPLATE="result: {unknown_var}"42 )43 def test_reporting_session(slacker_mock):44 with env_vars(LCC_SLACK_AUTH_TOKEN="sometoken", LCC_SLACK_CHANNEL="#chan"):45 run_suite_class(suite_sample, backends=[SlackReportingBackend()])46 slacker.Slacker.assert_called_once_with("sometoken", http_proxy=None, https_proxy=None)47 post_message = slacker.Slacker.return_value.chat.post_message48 assert post_message.call_args[0][0] == "#chan"49 assert "1 passed" in post_message.call_args[0][1]50 assert "0 failed" in post_message.call_args[0][1]51 def test_reporting_session_custom_proxy(slacker_mock):52 with env_vars(LCC_SLACK_AUTH_TOKEN="sometoken", LCC_SLACK_CHANNEL="#chan", LCC_SLACK_HTTP_PROXY="http://my.proxy"):53 run_suite_class(suite_sample, backends=[SlackReportingBackend()])54 slacker.Slacker.assert_called_once_with("sometoken", http_proxy="http://my.proxy", https_proxy="http://my.proxy")55 def test_reporting_session_custom_message_template(slacker_mock):56 with env_vars(LCC_SLACK_AUTH_TOKEN="sometoken", LCC_SLACK_CHANNEL="#chan", LCC_SLACK_MESSAGE_TEMPLATE="{passed_pct}"):57 run_suite_class(suite_sample, backends=[SlackReportingBackend()])...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Lemoncheesecake automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful