<html>
  <head>
    <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    <br>
    Here is the exact code:<br>
    $ cat testconfig.py <br>
    import pytest<br>
    <br>
    @pytest.fixture(scope='module')<br>
    def A(request):<br>
        return request.config.getoption("--A")<br>
    <br>
    $ cat testscript.py <br>
    import pytest<br>
     <br>
    skip_A = pytest.mark.skipif(<br>
        A(pytest.config.request),<br>
        reason="need --A option to run"<br>
    )<br>
    <br>
    <br>
    $ py.test testscript.py <br>
    ============================= test session starts
    ==============================<br>
    platform linux2 -- Python 2.7.12, pytest-2.8.7, py-1.4.31,
    pluggy-0.3.1<br>
    rootdir: /home/rjl/pytest, inifile: <br>
    collected 0 items / 1 errors <br>
    <br>
    ==================================== ERRORS
    ====================================<br>
    ________________________ ERROR collecting testscript.py
    ________________________<br>
    testscript.py:4: in &lt;module&gt;<br>
        A(pytest.config.request),<br>
    E   NameError: name 'A' is not defined<br>
    =========================== 1 error in 0.01 seconds
    ============================<br>
    <span class="n"><br>
      Instead of doing </span><br>
    <span class="n"><span class="n">pytest</span><span class="o">.</span><span
        class="n">config</span><span class="o">.</span><span class="n">getoption</span><span
        class="p"></span> more than one like this:<br>
      skip_A</span> <span class="o">=</span> <span class="n">pytest</span><span
      class="o">.</span><span class="n">mark</span><span class="o">.</span><span
      class="n">skipif</span><span class="p">(</span> <span class="n">pytest</span><span
      class="o">.</span><span class="n">config</span><span class="o">.</span><span
      class="n">getoption</span><span class="p">(</span><span class="s2">"--A"</span><span
      class="p">),</span> <span class="n">reason</span><span class="o">=</span><span
      class="s2">"need --A option to run"</span>
    <span class="p">)<br>
      I want to do it once in the config file.</span><br>
    I might want to use the value of the argument --A elsewhere so I
    don't want to do getoption many times.<br>
    <br>
    <div class="moz-cite-prefix">On 2016-10-14 01:16 PM, Bruno Oliveira
      wrote:<br>
    </div>
    <blockquote
cite="mid:CA+RQFffd+odKdriW-D1yPzWeaFLOdTD-F5rW8HzRf6mp3rUB_g@mail.gmail.com"
      type="cite">
      <div dir="ltr">
        <div class="markdown-here-wrapper" style="">
          <p style="margin:1.2em 0px!important">Hi,</p>
          <p style="margin:1.2em 0px!important">After fixing the missing
            “pytest” import, I get this error:</p>
          <pre style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;font-size:1em;line-height:1.2em;margin:1.2em 0px"><code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-radius:3px;display:inline;white-space:pre;overflow:auto;border-radius:3px;border:1px solid rgb(204,204,204);padding:0.5em 0.7em;display:block!important">foo.py:8: in &lt;module&gt;
    A(pytest.config.request),
E   AttributeError: 'Config' object has no attribute 'request'
</code></pre>
          <p style="margin:1.2em 0px!important">Please make sure to post
            a complete example and state clearly what your problem is
            and what you are trying to accomplish.</p>
          <p style="margin:1.2em 0px!important">Cheers,<br>
            Bruno.</p>
          <div
title="MDH:SGksPGRpdj48YnI+PC9kaXY+PGRpdj5BZnRlciBmaXhpbmcgdGhlIG1pc3NpbmcgInB5dGVzdCIgaW1wb3J0LCBJIGdldCB0aGlzIGVycm9yOjwvZGl2PjxkaXY+PGJyPjwvZGl2PjxkaXY+YGBgPC9k
aXY+PGRpdj48ZGl2PmZvby5weTo4OiBpbiAmbHQ7bW9kdWxlJmd0OzwvZGl2PjxkaXY+Jm5ic3A7
ICZuYnNwOyBBKHB5dGVzdC5jb25maWcucmVxdWVzdCksPC9kaXY+PGRpdj5FICZuYnNwOyBBdHRy
aWJ1dGVFcnJvcjogJ0NvbmZpZycgb2JqZWN0IGhhcyBubyBhdHRyaWJ1dGUgJ3JlcXVlc3QnPC9k
aXY+PC9kaXY+PGRpdj5gYGA8L2Rpdj48ZGl2Pjxicj48L2Rpdj48ZGl2PlBsZWFzZSBtYWtlIHN1
cmUgdG8gcG9zdCBhIGNvbXBsZXRlIGV4YW1wbGUgYW5kIHN0YXRlIGNsZWFybHkgd2hhdCB5b3Vy
IHByb2JsZW0gaXMgYW5kIHdoYXQgeW91IGFyZSB0cnlpbmcgdG8gYWNjb21wbGlzaC48L2Rpdj48
ZGl2Pjxicj48L2Rpdj48ZGl2PkNoZWVycyw8L2Rpdj48ZGl2PkJydW5vLjwvZGl2Pg=="
style="height:0;width:0;max-height:0;max-width:0;overflow:hidden;font-size:0em;padding:0;margin:0">​</div>
        </div>
      </div>
      <br>
      <div class="gmail_quote">
        <div dir="ltr">On Fri, Oct 14, 2016 at 2:03 PM James &lt;<a
            moz-do-not-send="true" href="mailto:bjlockie@lockie.ca">bjlockie@lockie.ca</a>&gt;
          wrote:<br>
        </div>
        <blockquote class="gmail_quote" style="margin:0 0 0
          .8ex;border-left:1px #ccc solid;padding-left:1ex">
          <div bgcolor="#FFFFFF" text="#000000" class="gmail_msg">
            <div class="m_2364392736954871010moz-text-html gmail_msg"
              lang="x-western">
              <div class="m_2364392736954871010WordSection1 gmail_msg">I
                have this in my config file:<br class="gmail_msg">
                @pytest.fixture(scope='module')<br class="gmail_msg">
                def A(request):<br class="gmail_msg">
                    return request.config.getoption("--A")<br
                  class="gmail_msg">
                 <br class="gmail_msg">
                skip_A = pytest.mark.skipif(<br class="gmail_msg">
                    A(pytest.config.request),<br class="gmail_msg">
                    reason="need --A option to run"<br class="gmail_msg">
                )<br class="gmail_msg">
                <br class="gmail_msg">
                but when I run it, it says <br class="gmail_msg">
                E   NameError: name 'A' is not defined<br
                  class="gmail_msg">
                 <br class="gmail_msg">
              </div>
            </div>
          </div>
          _______________________________________________<br
            class="gmail_msg">
          testing-in-python mailing list<br class="gmail_msg">
          <a moz-do-not-send="true"
            href="mailto:testing-in-python@lists.idyll.org"
            class="gmail_msg" target="_blank">testing-in-python@lists.idyll.org</a><br
            class="gmail_msg">
          <a moz-do-not-send="true"
            href="http://lists.idyll.org/listinfo/testing-in-python"
            rel="noreferrer" class="gmail_msg" target="_blank">http://lists.idyll.org/listinfo/testing-in-python</a><br
            class="gmail_msg">
        </blockquote>
      </div>
    </blockquote>
    <br>
  </body>
</html>