question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Not enforcing reason= with skipif/xfail markers

See original GitHub issue

Currently, when e.g. @pytest.mark.skipif(sys.platform != 'win32') is used rather than @pytest.mark.skipif("sys.platform != 'win32'") (condition as a string), pytest enforces that a reason="..." is given.

As far as I can see, the only place that reason is used is with -rs /-rx which isn’t used by default anyways. In other places where pytest can show additional information (like docstrings in --fixtures or descriptions in --markers), we show some default value instead of enforcing the user to specify something.

I was wondering: Should pytest do the same for reason= as well? Why not make it optional, and just report the location (without any description) in the skipped test summary for those cases?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:8 (8 by maintainers)

github_iconTop GitHub Comments

3reactions
The-Compilercommented, May 11, 2020

If there was a way to stringify the expression, that would solve the problem. Well this is Python so there probably is, but I’m not sure.

Probably possible but not pretty. Reminds me of things Hypothesis does. Money quote:

This file can approximately be considered the collection of hypothesis going to really unreasonable lengths to produce pretty output.

and

This is not a good function and I am sorry for it. Forgive me my sins, oh lord

1reaction
bluetechcommented, Jun 10, 2020

Closing per discussion.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Pytest not able to skip testcase in a class via marker skipif
With your example code, skipping tests via skipIf markers is not possible. First of all, let me clear the following: if you define...
Read more >
Working with custom markers — pytest documentation
mark.skip(reason=None): skip the given test function with an optional reason. Example: skip(reason="no way of currently testing this") ...
Read more >
7. Incomplete and Skipped Tests — PHPUnit 9.5 Manual
This misinterpretation leads to the test reports being useless – you cannot see whether a test is actually successful or just not yet...
Read more >
All the reasons you'll fail your driving test
Disobeying traffic signs, signals and road markings. Not stopping with all of your vehicle behind the line at a red traffic light; Driving...
Read more >
unittest — Unit testing framework — Python 3.11.1 ...
Unittest supports skipping individual test methods and even whole classes of tests. In addition, it supports marking a test as an “expected failure,”...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found