title: How to set current_user for pytest?
body: <p>I'm writing a unit test for a view that uses the current logged in user in a query:</p>
  
  <pre><code>@app.route('/vendors/create', methods=['GET', 'POST'])
  @login_required
  def create_vendors():
      vendor_form = VendorForm(request.form)
      if vendor_form.validate_on_submit():
          vendor = db.session.query(Vendors).filter(Vendors.name == vendor_form.name.data,
                                                    Vendors.users.contains(g.user)).first()
          if vendor:
              flash('There is a vendor with this name already.')
              return redirect(url_for('create_vendors', vendor_form=vendor_form))
          vendor = Vendors(name=vendor_form.name.data, aws_access_key=vendor_form.aws_access_key.data,
                           merchant_key=vendor_form.merchant_key.data, secret_key=vendor_form.secret_key.data)
          vendor.users.append(current_user)
          db.session.add(vendor)
          db.session.commit()
          return redirect(url_for('vendors'))
      return render_template('edit_vendor.html', vendor_form=vendor_form)
  </code></pre>
  
  <p>and the test:</p>
  
  <pre><code>def test_create_vendor(self):
      response = TestViews.client.post('/vendors/create', follow_redirects=True,
                                       data=dict(name='Name', aws_access_key='aws_access_key',
                                                 merchant_key='merchant_key',
                                                 secret_key='secret_key'))
      assert response.status_code == 200
      vendors = db.session.query(Vendors).filter(Vendors.aws_access_key == 'aws_access_key').all()
      assert len(vendors) == 1
      assert vendors[0].name == 'Name'
  </code></pre>
  
  <p>and in my settings <code>LOGIN_DISABLED = True</code>.</p>
  
  <p>My problem is that when running the test <a href="https://flask-login.readthedocs.io/en/latest/#flask_login.current_user" rel="noreferrer">current_user</a> is never set.</p>
  
  <p>I've tried logging in using the test client and wrapping my tests in a <code>with TestLogin.client:</code> but <code>current_user</code> is just never set. Any ideas on how to set it?</p>